Conda packed env does not point to right python after unpack

494 Views Asked by At

So, I create a conda env the usual way, but with a slight difference. I copy some extra folders to the env root so I can have them packed.

After packing to tar.gz they are there, but when unpacking and activating, it does not point to the right python executable. any ideas?

╭─ ~/Downloads  
╰─ mkdir -p my_env
╭─ ~/Downloads  
╰─ tar -xzf my_env.tar.gz -C my_env
╭─ ~/Downloads  
╰─ source my_env/bin/activate
╭─ ~/Downloads                                     my_env
╰─ which python
/usr/bin/python
1

There are 1 best solutions below

14
Gaarv On

There is an undocumented (probably on purpose, to avoid some user issues) --copy switch that allow you to have a "portable" conda env:

Example:

conda create -p /path/to/new-conda-env --copy python=3 pandas scikit-learn

The conda env created at this path can then be zipped and unzipped elsewhere on similar architecture (ie. linux x64 to linux x64). You can also manually add packages if necessary (copy to site-packages path).

I use this all the time with PySpark + Hadoop to ship all dependencies without having to install them on cluster.