requirements.txt depending on python version

前端 未结 2 432
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-04 18:38

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 in

2条回答
  •  隐瞒了意图╮
    2020-12-04 19:10

    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'
    

    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',
            ],
        },
    )
    

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

提交回复
热议问题