requirements.txt取决于python版本 [英] requirements.txt depending on python version

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

问题描述

我正在尝试使用六个将python2软件包移植到python3(不是我自己的),以使其与两者兼容.但是,requests.txt中列出的软件包之一现在已包含在python3 stdlib中,而pypi版本在python3中不起作用,因此我想有条件地将其排除在外.在setup.py中执行此操作很容易,我可以做类似的事情:

I'm trying to port a python2 package to python3 (not my own) using six so that it's compatible with both. However one of the packages listed in requirements.txt is now included in the python3 stdlib and the pypi version doesn't work in python3 so I want to conditionally exclude it. Doing this in setup.py is easy, I can just do something like:

if sys.version_info[0] == 2:
    requirements += py2_requirements
else:
    requirements += py3_requirements

但是我也希望Requirements.txt也能反映正确的列表.我在pip文档中找不到任何内容.有人知道怎么做,或者甚至有可能吗?

But I would like requirements.txt to reflect the correct list too. I can't find anything on this in the pip documentation. so does anyone know how to do it, or if it is even possible?

推荐答案

您可以使用环境标记可以在requirements.txt中实现,因为pip 6.0:

You can use the environment markers to achieve this in requirements.txt since pip 6.0:

SomeProject==5.4; python_version < '2.7'
SomeProject; sys_platform == 'win32'

setuptools也通过在setup.py中声明额外的要求来支持它:

It is supported by setuptools too by declaring extra requirements in setup.py:

setup(
    ...
    install_requires=[
        'six',
        'humanize',
    ],
    extras_require={
        ':python_version == "2.7"': [
            'ipaddress',
        ],
    },
)

另请参见需求说明. 字符串表示相应的Python命令的字符串版本.

See also requirement specifiers. And Strings for the string versions of corresponding Python commands.

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

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