【发布时间】: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 对除一个以外的所有包进行依赖解析?
我尝试过的事情......
- 我看到了:
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)
- 我还尝试对一个依赖项(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 年没有重大变化),但你最好找到一个替代方案。