在setup.py中根据安装的Python版本安装依赖项

7

我的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:来实现,但也许有更好的方法。


我找不到install_requires作为distutils.core.setup的参数,它似乎是遗留下来的setuptools。http://docs.python.org/2/distutils/apiref.html#distutils.core.setup - jrwren
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,
# [...]
)

1
现在有一种更好的方法,可以在这个答案中找到。 - ederag

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接