有没有办法指定要与setup.py中定义的python包一起使用的python版本?
我的setup.py当前是这样的:
from distutils.core import setup
setup(
name = 'macroetym',
packages = ['macroetym'], # this must be the same as the name above
version = '0.1',
description = 'A tool for macro-etymological textual analysis.',
author = 'Jonathan Reeve',
author_email = 'jon.reeve@gmail.com',
url = 'https://github.com/JonathanReeve/macro-etym',
download_url = 'https://github.com/JonathanReeve/macro-etym/tarball/0.1', # FIXME: make a git tag and confirm that this link works
install_requires = ['Click', 'nltk', 'pycountry', 'pandas',
'matplotlib'],
include_package_data = True,
package_data = {'macroetym': ['etymwm-smaller.tsv']},
keywords = ['nlp', 'text-analysis', 'etymology'],
classifiers = [],
entry_points='''
[console_scripts]
macroetym = macroetym.main:cli
''',
)这是一个命令行程序。我的脚本使用Python3运行,但是很多操作系统仍然默认使用Python2。如何指定要在此处使用的python版本?我似乎在the docs中找不到任何东西,但也许我没有找到正确的地方?
发布于 2016-05-14 02:05:25
对于较新版本的setuptools (24.2.0或更高版本)和较新版本的pip (9.0.0或更高版本),您可以使用python_requires:https://packaging.python.org/tutorials/distributing-packages/#python-requires
Python 3+:
python_requires='>=3',如果您的软件包用于Python 3.3和更高版本,但您还不愿意支持Python 4,请编写:
python_requires='~=3.3',如果您的软件包用于Python 2.6、2.7以及从3.3开始的所有版本的Python 3,请编写:
python_requires='>=2.6, !=3.0.*, !=3.1.*, !=3.2.*, <4',旧版本的旧答案/解决方法。
可以使用sys.version或platform.python_version()发出错误或警告
import sys
print(sys.version)
print(sys.version_info)
print(sys.version_info.major) # Returns 3 for Python 3或者:
import platform
print(platform.python_version())https://stackoverflow.com/questions/37216560
复制相似问题