Search code examples
pythonpipanacondaconda

Combining conda environment.yml with pip requirements.txt


I work with conda environments and need some pip packages as well, e.g. pre-compiled wheels from ~gohlke.

At the moment I have two files: environment.yml for conda with:

# run: conda env create --file environment.yml
name: test-env
dependencies:
- python>=3.5
- anaconda

and requirements.txt for pip which can be used after activating above conda environment:

# run: pip install -i requirements.txt
docx
gooey
http://www.lfd.uci.edu/~gohlke/pythonlibs/bofhrmxk/opencv_python-3.1.0-cp35-none-win_amd64.whl

Is there a possibility to combine them in one file (for conda)?


Solution

  • Pip dependencies can be included in the environment.yml file like this (docs):

    # run: conda env create --file environment.yml
    name: test-env
    dependencies:
    - python>=3.5
    - anaconda
    - pip
    - numpy=1.13.3  # pin version for conda
    - pip:
      # works for regular pip packages
      - docx
      - gooey
      - matplotlib==2.0.0  # pin version for pip
      # and for wheels
      - http://www.lfd.uci.edu/~gohlke/pythonlibs/bofhrmxk/opencv_python-3.1.0-cp35-none-win_amd64.whl
    

    It also works for .whl files in the same directory (see Dengar's answer) as well as with common pip packages.