Reputation: 1220
Is there a way to specify the minimum python version required for installing a module in pip?
I am trying to publish a package to pypi.
python setup.py sdist upload -r pypi
Is the command I am using. However in setup.py there is no way to specify that the minimum python version (in my case python 3.5) is needed to run this module.
Upvotes: 5
Views: 5378
Reputation: 94417
First thing is to document what minimal Python version is required for your package. Include that info in README and in setup.py
:
setup(
…
long_description=open('README.rst', 'rU').read(),
classifiers=[
…
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
…
],
…
)
Second, forbid bad versions at runtime somewhere near the top of setup.py
:
import sys
if sys.version_info < (3, 5):
raise RuntimeError("This package requres Python 3.5+")
Upvotes: 4
Reputation: 237
You can specify the version of the python required for your project by using:
python_requires='>=3.5'
The above code must be specified in setup.py
,also only versions 9.0.0 and higher of pip recognize the python_requires
metadata.
Additionally in setup.py
to specify the dependences:
setup(
install_requires=['dependent functions,classes,etc'],
)
Upvotes: 11