2011-05-21 59 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