Search code examples
pythonwindowspipdevelopment-environmentconda

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.


Solution

  • 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.