Combining conda environment.yml with pip requirements.txt
Pip dependencies can be included in the environment.yml
file like this (docs):
# run: conda env create --file environment.ymlname: test-envdependencies:- 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.
One can also use the requirements.txt
directly in the YAML. For example,
name: test-envdependencies: - python>=3.5 - anaconda - pip - pip: - -r requirements.txt
Basically, any option you can run with pip install
you can run in a YAML. See the Advanced Pip Example for a showcase of other capabilities.
Important Note
A previous version of this answer (and Conda's Advanced Pip Example) used a substandard file
URI syntax:
- -r file:requirements.txt
Pip v21.2.1 introduced stricter behavior for URI parsing and no longer supports this. See this answer for details.
Just want to add that adding a wheel in the directory also works. I was getting this error when using the entire URL:
HTTP error 404 while getting http://www.lfd.uci.edu/~gohlke/pythonlibs/f9r7rmd8/opencv_python-3.1.0-cp35-none-win_amd64.whl
Ended up downloading the wheel and saving it into the same directory as the yml file.
name: test-envdependencies:- python>=3.5- anaconda- pip- pip: - opencv_python-3.1.0-cp35-none-win_amd64.whl