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 = '[email protected]',
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
''',
)
これはコマンドラインプログラムです。私のスクリプトはPython 3で実行されていますが、多くのオペレーティングシステムではPython 2がデフォルトになっています。ここで使用するPythonのバージョンを指定するにはどうすればいいでしょうか?ドキュメント、でも、私が探している場所が間違っているのかもしれません。
ベストアンサー1
新しいバージョンの 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())