setup.py 中的 install_requires 取决于安装的 Python 版本 [英] install_requires in setup.py depending on installed Python version

查看:329
本文介绍了setup.py 中的 install_requires 取决于安装的 Python 版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 setup.py 看起来像这样:

My setup.py looks something like this:

from distutils.core import setup

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

在 Python 2.6(或更高版本)下,ssl 模块的安装失败:

Under Python 2.6 (or higher) the installation of the ssl module fails with:

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:但也许有更好的方法.

Is there a standard way to define dependencies only for specific python versions? Of course I could do it with if float(sys.version[:3]) < 2.6: but maybe there is a better way to do it.

推荐答案

这只是一个列表,所以你必须有条件地在上面的某个地方建立一个列表.像下面这样的事情很常见.

It's just a list, so somewhere above you have to conditionally build a list. Something like to following is commonly done.

import sys

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

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

这篇关于setup.py 中的 install_requires 取决于安装的 Python 版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆