【问题标题】:How can I have pip ignore all of the sub dependencies of a single dependency in a requirements.txt file?如何让 pip 忽略 requirements.txt 文件中单个依赖项的所有子依赖项?
【发布时间】:2022-01-17 08:11:08
【问题描述】:

我正在使用 python 的虚拟环境 (python3 -m venv venv) 和带有 requirements.txt 的 pip。我需要使用一个依赖于非常旧版本的请求(2.7.0)的包(python-particle)。我想使用更新版本的请求(2.25.0 或更高版本),但由于 python-particle 明确调用“requests==2.7.0”,因此在尝试使用更高版本的请求时出现错误。

有没有办法告诉 pip 用户请求的版本优先? 或者,有没有办法告诉 pip 对除一个以外的所有包进行依赖解析?

我尝试过的事情......

  1. 我看到了:

setup.py & pip: override one of the dependency's sub-dependency from requirements.txt

$ more requirements.txt 
pexpect>=3.3
python-dateutil>=2.4.2
pytz>=2015.4
six>=1.15.0
python-particle>=0.2

$ more constraints.txt 
requests>=2.25.0

但是当我尝试时我仍然收到错误:

ERROR: Cannot install -r requirements.txt (line 5) because these package versions have conflicting dependencies.

The conflict is caused by:
    python-particle 0.2 depends on requests==2.7.0
    The user requested (constraint) requests>=2.25.0

To fix this you could try to:
1. loosen the range of package versions you've specified
2. remove package versions to allow pip attempt to solve the dependency conflict

ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/user_guide/#fixing-conflicting-dependencies

我使用的 pip 版本是:

$ pip --version
pip 21.3.1 from /home/xyzzy/src/tools/venv/lib/python3.9/site-packages/pip (python 3.9)
  1. 我还尝试对一个依赖项(python-particle)使用--no-deps,但这不起作用。我对此尝试的 requirements.txt:
pexpect>=3.3
python-dateutil>=2.4.2
pytz>=2015.4
requests>=2.25.0
six>=1.15.0
python-particle>=0.2 --install-option="--no-deps"

来自 pip 的错误信息:

ERROR: Cannot install -r requirements.txt (line 6) and requests>=2.25.0 because these package versions have conflicting dependencies.

The conflict is caused by:
    The user requested requests>=2.25.0
    python-particle 0.2 depends on requests==2.7.0

To fix this you could try to:
1. loosen the range of package versions you've specified
2. remove package versions to allow pip attempt to solve the dependency conflict

ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/user_guide/#fixing-conflicting-dependencies

【问题讨论】:

  • 不幸的是,自从这个项目uses the package metadata to pin dependencies 以来,除了忽略冲突并明确安装包之外,您无能为力。包元数据中的过度约束几乎总是一个错误,因此可能值得项目维护人员要求他们不要这样做。虽然,这个项目看起来不活跃(6 年没有重大变化),但你最好找到一个替代方案。

标签: python pip


【解决方案1】:

也许使用--no-deps标志安装粒子,然后正常安装其余的requirements.txt?

pip install python-particle>=0.2
pip uninstall requests
pip install -r requirements.txt(从该文件中删除python-particle后)

使用这种方法你需要自己安装请求以外的所有粒子依赖,或者你可以试试这个

pip install python-particle>=0.2
pip uninstall requests
pip install -r requirements.txt(同样,此文件中没有粒子)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-21
    • 1970-01-01
    • 2013-11-28
    • 2016-08-21
    • 2021-08-05
    • 2016-10-24
    • 2019-06-28
    • 2010-10-07
    相关资源
    最近更新 更多