安装基于python版本的\u需要

安装基于python版本的\u需要,python,setuptools,distutils,distribute,install-requires,Python,Setuptools,Distutils,Distribute,Install Requires,我有一个模块,可以在Python2和Python3上工作。在Python=3.2中 比如: install_requires=[ "threadpool >= 1.2.7 if python_version < 3.2.0", ], install\u需要=[ “如果python_版本=1.2.7”, ], 如何做到这一点呢?这已经讨论过了,建议的方法是使用sys.version_info在setup.py中测试Python版本 import sys if sys.

我有一个模块,可以在Python2和Python3上工作。在Python=3.2中

比如:

 install_requires=[
    "threadpool >= 1.2.7 if python_version < 3.2.0",
 ],
install\u需要=[
“如果python_版本<3.2.0,线程池>=1.2.7”,
],
如何做到这一点呢?

这已经讨论过了,建议的方法是使用
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)
使用:

install\u需要=[
'线程池>=1.2.7;python_版本<“3.2.0”,
]

Setuptools的特定用法在其详细说明中有详细说明。上面显示的语法需要setuptools v36.2+。

此解决方案非常脆弱,有许多
pip
wheel
包的组合。当pip代表您构建控制盘时,计算的install_requires列表将写入控制盘元数据中,然后缓存的控制盘可能会在不同的Python版本上使用。谢谢。这曾经对我有用,后来就停止了。根据您的评论,我能够确定这是因为我最近将发布命令更改为
bdist\u wheel
。这样将无法生成正确的包元数据。避免。
install_requires=[
    'threadpool >= 1.2.7; python_version < "3.2.0"',
]