How can I specify a python version using setuptools? [duplicate]

依然范特西╮ 提交于 2019-12-05 05:45:07

With newer versions of setuptools (24.2.0 or above) and newer versions of pip (9.0.0 or above) you can use python_requires: https://packaging.python.org/tutorials/distributing-packages/#python-requires

Python 3+:

python_requires='>=3',

If your package is for Python 3.3 and up but you’re not willing to commit to Python 4 support yet, write:

python_requires='~=3.3',

If your package is for Python 2.6, 2.7, and all versions of Python 3 starting with 3.3, write:

python_requires='>=2.6, !=3.0.*, !=3.1.*, !=3.2.*, <4',

For older versions the old answer/workaround.

You can raise an error or warning using sys.version or platform.python_version()

import sys
print(sys.version)
print(sys.version_info)
print(sys.version_info.major)  # Returns 3 for Python 3

Or:

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