python - setup.py 中的 install_requires 取决于安装的 Python 版本

标签 python setuptools

<分区>

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

最佳答案

它只是一个列表,所以你必须在上面的某个地方有条件地构建一个列表。 通常会执行以下操作。

import sys

if sys.version_info < (2 , 6):
    REQUIRES = ['gevent', 'ssl', 'configobj', 'simplejson', 'mechanize'],
else:
    REQUIRES = ['gevent', 'configobj', 'simplejson', 'mechanize'],

setup(
# [...]
    install_requires=REQUIRES,
# [...]
)

关于python - setup.py 中的 install_requires 取决于安装的 Python 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6080646/

相关文章:

python 包 : how to depend on the latest version of a separate package

python - 如何让setup.py安装多个顶级包?

python - 如何在不构建其 C 扩展的情况下 pip 安装包?

python - 使用 API key 进行 Urllib2 身份验证

仅对正数求和的Python程序

python - Django "deconstruct"模型字段函数的用途是什么?

python - setuptools:使用源文件夹中的 setup.py 从 'project' 导入

python - "unrecognized .svn/entries format"使用扩建

python - 如何解码 matplotlib 的 Colormap 中的颜色映射?

python - 容易出错的事情