Python 将 conda environment.yml 与 pip requirements.txt 结合使用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35245401/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Combining conda environment.yml with pip requirements.txt
提问by bastelflp
I work with conda environments and need some pip packages as well, e.g. pre-compiled wheels from ~gohlke.
我使用 conda 环境并且还需要一些 pip 包,例如来自~gohlke 的预编译轮子。
At the moment I have two files: environment.yml
for conda with:
目前我有两个文件:environment.yml
对于 conda 与:
# 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:
和requirements.txt
用于PIP可以上述环境康达激活后使用:
# 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)?
是否有可能将它们组合在一个文件中(对于 conda)?
采纳答案by bastelflp
Pip dependencies can be included in the environment.yml
file like this (docs):
Pip 依赖项可以environment.yml
像这样 ( docs)包含在文件中:
# run: conda env create --file environment.yml
name: test-env
dependencies:
- python>=3.5
- anaconda
- pip
- pip:
# works for regular pip packages
- docx
- gooey
# 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.
它也适用.whl
于同一目录中的文件(参见Dengar 的回答)以及常见的 pip 包。
回答by Dengar
Just want to add that adding a wheel in the directory also works. I was getting this error when using the entire URL:
只想补充一点,在目录中添加一个轮子也可以。使用整个 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.
最终下载了轮子并将其保存到与 yml 文件相同的目录中。
name: test-env
dependencies:
- python>=3.5
- anaconda
- pip
- pip:
- opencv_python-3.1.0-cp35-none-win_amd64.whl
回答by merv
One can also use the requirements.txt
directly in the YAML. For example,
也可以requirements.txt
直接在 YAML 中使用。例如,
name: test-env
dependencies:
- python>=3.5
- anaconda
- pip
- pip:
- -r file:requirements.txt
Basically, any option you can run with pip install
you can run in a YAML. See the Advanced Pip Examplefor a showcase of other capabilities.
基本上,您可以使用的任何选项都可以pip install
在 YAML 中运行。有关其他功能的展示,请参阅高级 Pip 示例。