install_requires based on python version

荒凉一梦 提交于 2019-11-29 22:53:13

setuptools has support for this using environment markers.

install_requires=[
    'enum34;python_version<"3.4"',
    'pywin32 >= 1.0;platform_system=="Windows"'
]

Use of this is detailed in the official documentation. Based on the change log was added in v20.5, but the implementation wasn't stable until v20.8.1 (which was only a gap of 15 days).


Original Answer (still valid, but might be deprecated in the future):

setuptools has support for this using within the extras_require argument.

The format is the following:

extras_require={
    ':python_version=="2.7"': ["mock"],
},

It will support the other comparison operators.


Sadly, it is not mentioned in the documentation. While looking for answers, I found PEP-426 talking about "environment markers". With that phrase I was able to find a setuptools ticket with the following comment:

I've successfully used the markers feature for selectively and declaratively requiring a dependency. See backports.unittest_mock for an example. Through the 'extras', mock will be required, but only on Python 2. When I can rely on Setuptools 17.1, I can change that dependency to python_version < "3.3".

sleepycal

This has been discussed here, it would appear the recommend way is to test for the Python version inside your setup.py using sys.version_info;

import sys

if sys.version_info >= (3,2):
    install_requires = ["threadpool >= 1.2.7"]
else:
    install_requires = ["threadpool >= 1.2.3"]

setup(..., install_requires=install_requires)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!