I have a Python package that only runs on Python 2. It has the following classifiers in its setup.py:
setup(
# ...
classifiers=[
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2 :: Only',
])
However, if I create a virtualenv with Python 3, pip happily installs this package.
How do I prevent the package being installed? Should my setup.py throw an error based on sys.version_info
? Can I stop pip even downloading the package?
If you want to determine whether Python2 or Python3 is running, you can check the major version with this sys. version_info. major . 2 means Python2, and 3 means Python3.
pip installation To use pip, first install a custom version of Python 2. pip is then installed with it. You can then use the pip command to create a virtualenv and install modules.
In setup.py, add this:
import sys
if sys.version_info[0] != 2:
sys.stderr.write("This package only supports Python 2.\n")
sys.exit(1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With