简体   繁体   English

安装pip需求时忽略一些需求

[英]Ignoring some requirements when installing pip requirements

I am using requirements.txt to install requirements for my virtualenv.我正在使用requirements.txt为我的 virtualenv 安装需求。 I use ansible for deployments which installs requirements on remote hosts.我将 ansible 用于在远程主机上安装要求的部署。

Problem:问题:

  1. Ignoring some requirements忽略一些要求

  2. Ignoring already installed requirements (something like pip freeze and if the package shows up, don't install it and don't even upgrade)忽略已安装的要求(例如pip freeze并且如果包出现,请不要安装它,甚至不要升级)

Solutions according to me:根据我的解决方案:

  1. I can grep installed packages and make a requirements2.txt having only the ones needed.我可以 grep 安装的软件包并制作一个只有需要的requirements2.txt (Also, remove packages being installed from GIT) (另外,从 GIT 中删除正在安装的包)

  2. I don't understand what --ignore-installed would do in this case?我不明白--ignore-installed在这种情况下会做什么?

  3. Any other solution?还有其他解决办法吗?

For selective dependencies installing, the only way is indeed to grep/filter the requirements.txt file according to your criteria.对于选择性依赖项安装,唯一的方法确实是根据您的标准对requirements.txt文件进行 grep/过滤。 However, there are few ready solutions that might be of use:但是,很少有现成的解决方案可能有用:


If you have a virtualenv and only need to quickly upgrade it to the new requirements or version restrictions, but do not upgrade if the existing packages meet the criteria, you can use如果你有一个 virtualenv 并且只需要快速升级到新的要求或版本限制,但如果现有包符合条件不升级,你可以使用

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

As the manual says:正如手册所说:

--upgrade-strategy <upgrade_strategy> Determines how dependency upgrading should be handled. --upgrade-strategy <upgrade_strategy>确定应如何处理依赖项升级。 "eager" - dependencies are upgraded regardless of whether the currently installed version satisfies the requirements of the upgraded package(s). “eager” - 无论当前安装的版本是否满足升级包的要求,依赖项都会升级。 "only-if-needed" - are upgraded only when they do not satisfy the requirements of the upgraded package(s). “only-if-needed” - 仅当它们不满足升级包的要求时才升级。


For the optional dependencies, the typical solution is the setuptools' extra requirements .对于可选的依赖项,典型的解决方案是 setuptools 的额外要求 For example, I use it for the development & doc-building requirements:例如,我将它用于开发和文档构建要求:

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

Then you can install it as follows, both from the PyPI/DevPI repos, and locally (as an editable library):然后您可以按如下方式安装它,从 PyPI/DevPI 存储库和本地(作为可编辑库):

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

You can define any names for the "extra modes" with optional dependencies.您可以为具有可选依赖项的“额外模式”定义任何名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM