【发布时间】:2014-01-31 15:44:32
【问题描述】:
我有一个适用于 python 2 和 python 3 的模块。在 Python=3.2。
类似:
install_requires=[
"threadpool >= 1.2.7 if python_version < 3.2.0",
],
如何做到这一点?
【问题讨论】:
标签: python setuptools distutils distribute install-requires
我有一个适用于 python 2 和 python 3 的模块。在 Python=3.2。
类似:
install_requires=[
"threadpool >= 1.2.7 if python_version < 3.2.0",
],
如何做到这一点?
【问题讨论】:
标签: python setuptools distutils distribute install-requires
install_requires=[
'threadpool >= 1.2.7; python_version < "3.2.0"',
]
Setuptools 的具体用法在他们的documentation 中有详细说明。上面显示的语法需要 setuptools v36.2+ (change log)。
【讨论】:
这已在here 进行过讨论,看来推荐的方法是使用sys.version_info 测试setup.py 中的Python 版本;
import sys
if sys.version_info >= (3,2):
install_requires = ["threadpool >= 1.2.7"]
else:
install_requires = ["threadpool >= 1.2.3"]
setup(..., install_requires=install_requires)
【讨论】:
pip 和 wheel 包的组合。当 pip 代表您构建轮子时,计算出来的 install_requires 列表会写入轮子元数据中,然后缓存的轮子可能会在不同的 Python 版本上使用。
bdist_wheel。