setup.py中的install_requires依赖于已安装的Python版本
我的setup.py文件大致是这样的:
from distutils.core import setup
setup(
[...]
install_requires=['gevent', 'ssl', 'configobj', 'simplejson', 'mechanize'],
[...]
)
在Python 2.6(或更高版本)下,安装ssl模块会失败,错误信息是:
ValueError: This extension should not be used with Python 2.6 or later (already built in), and has not been tested with Python 2.3.4 or earlier.
有没有什么标准的方法可以只为特定的Python版本定义依赖关系?当然,我可以用if float(sys.version[:3]) < 2.6:
来实现,但也许还有更好的方法。
1 个回答
12
这只是一个列表,所以在上面的代码中,你需要根据条件来创建这个列表。通常会像下面这样做。
import sys
if sys.version_info < (2 , 6):
REQUIRES = ['gevent', 'ssl', 'configobj', 'simplejson', 'mechanize'],
else:
REQUIRES = ['gevent', 'configobj', 'simplejson', 'mechanize'],
setup(
# [...]
install_requires=REQUIRES,
# [...]
)