如何处理setup.py覆盖子包依赖
How to deal with setup.py overwriting sub-package dependencies
我面临的问题是setuptools覆盖了子包的依赖要求。
示例:
setup.py
import os
from setuptools import setup
setup(
name="test",
version="0.1",
author="myself",
author_email="info@example.com",
description="How to manage dependencies?",
license="MIT",
classifiers=[
"Development Status :: 3 - Alpha"
],
zip_safe=False,
install_requires=[
'dependency-injector',
]
)
通过python setup.py install
安装成功
输出:
(venv) alex@ws:~$ pip freeze
dependency-injector==3.14.12
six==1.12.0
test==0.1
如果你使用以下 setup.py 包括六个作为依赖项(因为你的包中需要它),那么你会遇到问题,因为依赖注入器也需要尽管他们定义了固定的版本范围,但依赖关系。
import os
from setuptools import setup
setup(
name="test",
version="0.1",
author="myself",
author_email="info@example.com",
description="How to manage dependencies?",
license="MIT",
classifiers=[
"Development Status :: 3 - Alpha"
],
zip_safe=False,
install_requires=[
'dependency-injector',
'six'
]
)
输出:
error: six 1.13.0 is installed but six<=1.12.0,>=1.7.0 is required by {'dependency-injector'}
(venv) alex@ws:~$ pip freeze
dependency-injector==3.14.12
six==1.13.0
test==0.1
可以肯定的是,一个可行的解决方案只是重复依赖注入器使用的相同的六个版本范围(请参阅他们的回购中的 requirements.txt 文件),尽管我真的很想避免这种重复的依赖定义,因为例如dependency-injector 可能会升级六个版本的依赖项,因此我还需要更新我的包。所以我会一直尝试模仿他们的要求,这是不好的做法。
我认为实际上唯一干净的解决方案是 setuptools 构建一个依赖树,然后使用匹配所有依赖项要求的版本。
这现实吗?在上述情况下如何实现或推荐的最佳做法是什么?
TL;DR 的答案是 pip
当前没有依赖项解决程序。
pip
的问题跟踪器上有一个关于该主题的持续问题:https://github.com/pypa/pip/issues/988
他们说的是目前 pip
的行为是 "first found wins",所以你的顶级 six
依赖在 dependency-injector
的 six
依赖之前被解析,这这就是为什么你最后安装了最新的 six
版本。
关于 python setup.py install
与 pip install .
的问题,这两个命令之间似乎存在细微差别。他们内部使用的工具不一样,一般推荐的命令是pip install .
我面临的问题是setuptools覆盖了子包的依赖要求。
示例:
setup.py
import os
from setuptools import setup
setup(
name="test",
version="0.1",
author="myself",
author_email="info@example.com",
description="How to manage dependencies?",
license="MIT",
classifiers=[
"Development Status :: 3 - Alpha"
],
zip_safe=False,
install_requires=[
'dependency-injector',
]
)
通过python setup.py install
输出:
(venv) alex@ws:~$ pip freeze
dependency-injector==3.14.12
six==1.12.0
test==0.1
如果你使用以下 setup.py 包括六个作为依赖项(因为你的包中需要它),那么你会遇到问题,因为依赖注入器也需要尽管他们定义了固定的版本范围,但依赖关系。
import os
from setuptools import setup
setup(
name="test",
version="0.1",
author="myself",
author_email="info@example.com",
description="How to manage dependencies?",
license="MIT",
classifiers=[
"Development Status :: 3 - Alpha"
],
zip_safe=False,
install_requires=[
'dependency-injector',
'six'
]
)
输出:
error: six 1.13.0 is installed but six<=1.12.0,>=1.7.0 is required by {'dependency-injector'}
(venv) alex@ws:~$ pip freeze
dependency-injector==3.14.12
six==1.13.0
test==0.1
可以肯定的是,一个可行的解决方案只是重复依赖注入器使用的相同的六个版本范围(请参阅他们的回购中的 requirements.txt 文件),尽管我真的很想避免这种重复的依赖定义,因为例如dependency-injector 可能会升级六个版本的依赖项,因此我还需要更新我的包。所以我会一直尝试模仿他们的要求,这是不好的做法。
我认为实际上唯一干净的解决方案是 setuptools 构建一个依赖树,然后使用匹配所有依赖项要求的版本。 这现实吗?在上述情况下如何实现或推荐的最佳做法是什么?
TL;DR 的答案是 pip
当前没有依赖项解决程序。
pip
的问题跟踪器上有一个关于该主题的持续问题:https://github.com/pypa/pip/issues/988
他们说的是目前 pip
的行为是 "first found wins",所以你的顶级 six
依赖在 dependency-injector
的 six
依赖之前被解析,这这就是为什么你最后安装了最新的 six
版本。
关于 python setup.py install
与 pip install .
的问题,这两个命令之间似乎存在细微差别。他们内部使用的工具不一样,一般推荐的命令是pip install .