2011-05-21 64 views
6

我setup.py看起来是这样的:在Python的install_requires在setup.py取决于安装Python版本

from distutils.core import setup 

setup(
    [...] 
    install_requires=['gevent', 'ssl', 'configobj', 'simplejson', 'mechanize'], 
    [...] 
) 

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:做到这一点,但也许有更好的方法来做到这一点。

+0

我找不到install_requires作为distutils.core.setup的参数,它似乎从setuptools中遗留下来。 http://docs.python.org/2/distutils/apiref.html#distutils.core.setup – jrwren 2013-04-23 20:40:20

回答

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, 
# [...] 
) 
+0

现在有一个更好的方法,在[这个答案]中描述(https://stackoverflow.com/a/32643122/ 3565696) – ederag 2018-01-07 10:17:05