Skip to content

Instantly share code, notes, and snippets.

@pmbaumgartner
Last active October 14, 2024 08:28
Show Gist options
  • Save pmbaumgartner/2626ce24adb7f4030c0075d2b35dda32 to your computer and use it in GitHub Desktop.
Save pmbaumgartner/2626ce24adb7f4030c0075d2b35dda32 to your computer and use it in GitHub Desktop.
Conda-Pack Windows Instructions

Packing Conda Environments

You must be using conda for this approach. You will need conda installed on the Source machine and the Target machine. The Source machine must have an internet connection, the Target does not. The OS in both environments must match; no going from macOS to Win10 for example.

1. (Source) Install conda-pack in your base python environment.

conda install -c conda-forge conda-pack

2. (Source) Create a new environment that you'll replicate.

Note: I've had some issues with python 3.8 envs, so try 3.7 in your new environment. See here.

conda create -n env-to-pack python=3.7

3. (Source) Install conda packages into your new environment.

Note: Prefer packages from conda as much as possible. Packages from pip are not guaranteed to work.

conda activate env-to-pack
conda install <whatever>

4. (Source) Switch back to base environment and pack up your environment.

conda activate base
conda pack -n env-to-pack -o packed-env.tar.gz

5. (Source > Target) Copy the packed-env.tar.gz from the source environment to the target environment.

6. (Target) Unpack the tar.gz environment file to where you want the environment to go

Note: On Windows, you can do this with 7-zip. It'll take one step to decompress the gzip and another step to unpack the tar.

7. (Target) Unpack the environment and activate it

Note: Be sure you're using standard Command Prompt (cmd.exe) on Windows, not Anaconda Prompt or PowerShell; those shells don't correctly add the right files to PATH.

cd unpacked-environment
.\Scripts\activate.bat
.\Scripts\conda-unpack.exe

8. (Target) Run Python in your unpacked-environment

The prompt should tell you that you're in the right environment after the last step, so you should see something like the following, which will allow you to then run python within this environment

(unpacked-env-name) C:\Some\Path\Where\Your\Environment\Is> python
@Chris55
Copy link

Chris55 commented Feb 9, 2024

On step 6, had error when using 7zip, similar to this:

7zip has problems extracting POSIX tar archives due to @PaxHeader files

I used tar from 'Git for Windows' as suggested and worked fine.

@gmontcheuil
Copy link

Thank you for this tip, it work very well for me.

Note that Windows now come with a tar executable in the PATH (C:\Windows\System32\tar.exe in my case).

Based on TAR - Windows CMD - SS64.com, it's since 2018.

BSD TAR.exe was added to Windows 10 (1803) from build 17063 or later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment