【问题标题】:install_requires in setup.py depending on installed Python version [duplicate]setup.py 中的 install_requires 取决于已安装的 Python 版本 [重复]
【发布时间】:2011-08-30 03:41:42
【问题描述】:

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

【问题讨论】:

标签: python setuptools


【解决方案1】:

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

import sys

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

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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2019-12-10
  • 2020-10-24
  • 2014-01-31
  • 2018-04-05
  • 2020-06-10
  • 1970-01-01
  • 2021-10-26
  • 2019-09-24
相关资源
最近更新 更多