gpt4 book ai didi

python - 安装pip要求时忽略一些要求

转载 作者:太空宇宙 更新时间:2023-11-04 05:16:02 26 4
gpt4 key购买 nike

我正在使用 requirements.txt 为我的 virtualenv 安装要求。我使用 ansible 进行部署,在远程主机上安装需求。

问题:

  1. 忽略一些要求

  2. 忽略已安装的要求(如 pip freeze,如果出现包,则不要安装它,甚至不要升级)

我的解决方案:

  1. 我可以 grep 已安装的包并制作一个只包含所需包的 requirements2.txt。 (另外,从 GIT 中删除正在安装的包)

  2. 我不明白 --ignore-installed 在这种情况下会做什么?

  3. 还有其他解决方案吗?

最佳答案

对于选择性依赖安装,唯一的方法确实是 grep/filter requirements.txt根据您的标准归档。但是,几乎没有可用的现成解决方案:


如果你有一个virtualenv,只需要快速升级到新的要求或版本限制,但如果现有的包符合条件就不要升级,你可以使用

pip install -U --upgrade-strategy=only-if-needed  ...

正如手册所说:

--upgrade-strategy <upgrade_strategy> Determines how dependency upgrading should be handled. "eager" - dependencies are upgraded regardless of whether the currently installed version satisfies the requirements of the upgraded package(s). "only-if-needed" - are upgraded only when they do not satisfy the requirements of the upgraded package(s).


对于可选依赖项,典型的解决方案是设置工具的 extra requirements .例如,我将它用于开发和文档构建要求:

# setup.py
setup(
...,
extras_require={
'dev': ["pdbpp", "ipython"],
'doc': ["sphinx"],
},
)

然后您可以按如下方式从 PyPI/DevPI 存储库和本地(作为可编辑库)安装它:

pip install mylib[dev]
pip install mylib[doc]
pip install -e .[doc,dev]

您可以为具有可选依赖项的“额外模式”定义任何名称。

关于python - 安装pip要求时忽略一些要求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41678951/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com