首页 > 解决方案 > Pip 为使用 Poetry 构建的库安装了不必要的冲突依赖项

问题描述

^我已经使用 Poetry 和版本约束指定了库的依赖关系。如果您只是安装最新版本的依赖项,则依赖项会发生冲突,但它们是可解析的并poetry install正确解析它们。但是,pip installfrompyproject.toml不能正确解决它们并产生冲突。

最小的例子

目录结构:

poetry_poc/
poetry_poc/__init__.py
pyproject.toml

__init__.py文件为空,内容为pyproject.toml

[tool.poetry]
name = "poetry_poc"
version = "0.1.0"
description = "minimal example of issue"
authors = ["Your Name <you@example.com>"]

[tool.poetry.dependencies]
python = "^3.6"
requests = "^2.18.4"
snowflake-connector-python = "^2.2.9"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"

该约束snowflake-connector-python = "^2.2.9"只能在 2.2.9 版本中解决,因此可以安装。然后该库需要 requests<2.24.0,并且我的项目指定requests^2.18.4,因此 2.18.4 和 2.23.x 之间的任何版本都可以正常工作,但 pip 安装请求 2.24.0 并报告:

ERROR: snowflake-connector-python 2.2.9 has requirement requests<2.24.0, but you'll have requests 2.24.0 which is incompatible. 

我已经在一个全新的虚拟环境中尝试过这个,只安装了 pip 20.1.1 和 setuptools 39.0.1,然后我运行pip install . --no-cache-dir,所以每个依赖项都将重新下载。我的诗歌版本是1.0.10。

这是预期的行为 - pip 不会解决这些类型的冲突 - 还是我做错了什么,或者这是一个错误?

标签: pippython-packagingpython-poetry

解决方案


推荐阅读