Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exporting a conda environment with local pip installs

I have exported my currently active environment with

conda env export > environment.yml

This is very convenient since it keeps track of both conda and pip installed packages. However, I have a few packages (shapely and basemap for example) installed locally by pip from a .whl file from Christoph Gohlke's compiled packages for Windows. When I try to recreate my environment by

conda env create -f environment.yml

pip returns with an error since it cannot find these packages in its index (obviously). Is there a way to tell pip in the conda export step where to look for these local packages? The .whl files can be assumed to be in the same directory as the environment.yml file.

like image 719
user787267 Avatar asked Jun 30 '16 06:06

user787267


People also ask

Can I use pip install in conda environment?

You can install pip in the current conda environment with the command conda install pip , as discussed in Using pip in an environment. If there are instances of pip installed both inside and outside the current conda environment, the instance of pip installed inside the current conda environment is used.

Can you export conda environment?

With conda, you can create, export, list, remove, and update environments that have different versions of Python and/or packages installed in them. Switching or moving between environments is called activating the environment. You can also share an environment file.

Can pip and conda be used together?

pip is the standard package manager for python, meaning you can use it both inside and outside of Anaconda.


1 Answers

There's no way to actually get it to create entries for the .whl file automatically from what I'm aware of.

The simplest way to get this to work is by manually altering the environment.yml file and adding the .whl file in the list under - pip:. I tried this by downloading the .whl package for nose and placing it in the same directory as my env.yml file, the structure looked like this:

name: python3_test
dependencies:
- openssl=1.0.2h=1
- pip=8.1.2=py35_0
- python=3.5.1=5
- readline=6.2=2
- setuptools=23.0.0=py35_0
- sqlite=3.13.0=0
- tk=8.5.18=0
- wheel=0.29.0=py35_0
- xz=5.2.2=0
- zlib=1.2.8=3
- pip:
   - nose-1.3.7-py3-none-any.whl

If it is located in a different directory, just supply the directory. The path, of course, should be valid when issuing conda create env.

The pip command issued when running conda env create -n <name> -f <file.yml> is a pretty straightforward install so the semantics of installing with pip from the command line should be similar. Heck, you could even add the url for the .whl file in the requirements.yml and the installation would still go down smoothly. Again, keeping the rest the same and using the url for downloading nose:

- pip:
   - https://pypi.python.org/packages/15/d8/dd071918c040f50fa1cf80da16423af51ff8ce4a0f2399b7bf8de45ac3d9/nose-1.3.7-py3-none-any.whl#md5=3135984cc9cfcbe5d9c46e166d6743b0

Using any url shouldn't cause any issue.

like image 185
Dimitris Fasarakis Hilliard Avatar answered Oct 23 '22 14:10

Dimitris Fasarakis Hilliard