python - 仅使用 "conda install --yes --file requirements.txt"安装可用的软件包而不会出错

标签 python pip anaconda

通过以下命令使用 Conda 在 requirements.txt 中安装包时

conda install --yes --file requirements.txt

如果 requirements.txt 中的包不可用,则会引发“无包错误”,如下所示:

Using Anaconda Cloud api site https://api.anaconda.org

Fetching package metadata: ....

Error: No packages found in current linux-64 channels matching: nimfa ==1.2.3

You can search for this package on anaconda.org with

anaconda search -t conda nimfa ==1.2.3

是否可以更改此行为,而不是引发错误,以便在 requirements.txt 中安装所有可用的包,并对不可用的包发出警告?

我想要这个,因为错误说的包 nimfa 不可用,可以 pip 安装。因此,如果我可以更改 conda install --yes --file requirements.txt 的行为以仅对不可用的包发出警告,我可以使用命令 pip install -r 跟进.travis.yml 中的需求.txt,因此 TravisCI 会尝试从任何可用的地方安装它。

最佳答案

我最终只是遍历文件的行

$ while read requirement; do conda install --yes $requirement; done < requirements.txt

编辑:如果你想使用 pip 安装一个包,如果它不能通过 conda 获得,试试这个:

$ while read requirement; do conda install --yes $requirement || pip install $requirement; done < requirements.txt

编辑:如果您使用的是 Windows(归功于 @Clay):

$ FOR /F "delims=~" %f in (requirements.txt) DO conda install --yes "%f" || pip install "%f"

关于python - 仅使用 "conda install --yes --file requirements.txt"安装可用的软件包而不会出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35802939/

相关文章:

python - 在构建 Pandas DataFrame 时使用逻辑运算符

python - pip3 : Command Not Found on OS X

python - 如何找到虚拟环境中的安装路径?

python - SciPy 模块名称和函数无法定义

python - 使用 flask 和 flask-socketio 配置 nginx、uwsgi

python - python有没有C/C++之类的double import?

Python/wxPython : Doing work continuously in the background

python - 将 Wagtail 与 django 2.0 结合使用

python - pip 命令未被识别

macos - MacoS 上 "Matplotlib is building the font cache using fc-list. This may take a moment."的问题