真实打包4个互相版本冲突的本地wheel,对比分步pip install和合并pip install在同一个冲突下给出的真实不同结果。
代码# libc 1.0.0 和 libc 2.0.0 两个版本各打一个wheel # pkga 的 pyproject.toml: dependencies = ["libc<2.0"] # pkgb 的 pyproject.toml: dependencies = ["libc>=2.0"] python3 -m build --wheel --outdir wheelhouse libc1 python3 -m build --wheel --outdir wheelhouse libc2 python3 -m build --wheel --outdir wheelhouse pkga python3 -m build --wheel --outdir wheelhouse pkgb → 真实生成4个wheel文件,libc-1.0.0、libc-2.0.0、pkga-1.0.0、pkgb-1.0.0
pip install pkga → 真实装上 libc-1.0.0 + pkga-1.0.0
pip install pkgb →
Attempting uninstall: libc
Found existing installation: libc 1.0.0
Uninstalling libc-1.0.0:
Successfully uninstalled libc-1.0.0
ERROR: pip's dependency resolver does not currently take into account all the
packages that are installed. This behaviour is the source of the following
dependency conflicts.
pkga 1.0.0 requires libc<2.0, but you have libc 2.0.0 which is incompatible.
Successfully installed libc-2.0.0 pkgb-1.0.0 ← 真实照样"成功"安装了这是本文认为最容易被误解的真实行为:这条ERROR只是一句诊断信息,不是安装失败——命令的退出码是0,libc-2.0.0和pkgb-1.0.0真实都被装进了环境,libc-1.0.0真实被卸载。这一步执行完,环境里同时装着要求libc<2.0的pkga和真实版本是2.0.0的libc——这是一个真实处于冲突状态、但pip不会阻止你继续用下去的环境,如果pkga的代码里真的用到了libc 1.x才有、2.x已经删掉的API,运行时才会真实报错,而这个报错发生的时间点跟"装错依赖"这个真正原因之间,可能隔了很久。
pip install pkga pkgb →
INFO: pip is looking at multiple versions of pkgb to determine which version
is compatible with other requirements. This could take a while.
ERROR: Cannot install pkga==1.0.0 and pkgb==1.0.0 because these package
versions have conflicting dependencies.
The conflict is caused by:
pkga 1.0.0 depends on libc<2.0
pkgb 1.0.0 depends on libc>=2.0
ERROR: ResolutionImpossible: ...
之后检查: pip list → 只有pip自己,libc/pkga/pkgb真实一个都没装每一步都是本文上面用真实打包的wheel跑出来的原始结果。
python -m build / pip install