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
@lucheroni
Copy link

lucheroni commented Aug 1, 2021

Hello.

I tried the sequence indicated. Win10 pro to Win10 pro, laptops with very similar hardware. Environment to be tranferred prepared with python 3.7.
-> The target laptop installation has a space in the username <-, and Anaconda installed.

I'm able to get to

cd unpacked-environment
.\Scripts\activate.bat

but when I issue

.\Scripts\conda-unpack.exe

I get

failed to create process

Is that to be expected? Should I give up with conda-pack in my case?

@pmbaumgartner
Copy link
Author

pmbaumgartner commented Aug 8, 2021 via email

@3BBUAE
Copy link

3BBUAE commented Aug 9, 2021

I think things should be fine, even if that step fails. Were you able to use the environment?

On Sun, Aug 1, 2021, 5:36 AM lucheroni @.> wrote: @.* commented on this gist. ------------------------------ Hello. I tried the sequence indicated. Win10 pro to Win10 pro, laptops with very similar hardware. Environment to be tranferred prepared with with python 3.7. -> The target laptop installation has a space in the username <-, and Anaconda installed. I'm able to get to cd unpacked-environment .\Scripts\activate.bat but when I issue .\Scripts\conda-unpack.exe I get failed to create process Is that to be expected? Should I give up with conda-pack in my case? — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://gist.github.com/2626ce24adb7f4030c0075d2b35dda32#gistcomment-3838571, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABG65TKOBCFF7Y6FZ2PNKQ3T2UITDANCNFSM5BK6OTQQ .

I get the same error, after trying to use the conda-unpack.exe i get failed to create process.

@jganseman
Copy link

This Gist has saved me today - thanks! Voting to integrate this in the conda-pack docs :)

@sachinbdoshi
Copy link

when I run the conda-unpack.exe command I get following error, what have I done wrong here ?
image

@CarlosML27
Copy link

when I run the conda-unpack.exe command I get following error, what have I done wrong here ? image

Hello mate! I'm having the exact same issue. Did you manage to solve it?

@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