What can we put in a setup.py
file to prevent pip from collecting and attempting to install a package when using an unsupported Python version?
For example magicstack
is a project listed with the trove classifier:
Programming Language :: Python :: 3 :: Only
So I expect the following behaviour if pip --version
is tied to python 2.7:
$ pip install magicstack
Collecting magicstack
Could not find a version that satisfies the requirement magicstack (from versions: )
No matching distribution found for magicstack
But the actual behavior is that pip collects a release, downloads it, attempts to install it, and fails. There are other Python3-only releases, curio
for example, which actually install fine - because the setup.py
didn't use anything Python 3 specific - only to fail at import time when some Python 3 only syntax is used. And I'm sure there are packages which install OK, import OK, and maybe only fail at runtime!
What is the correct method to specify your supported Python versions in a way that pip will respect? I've found a workaround, involving uploading only a wheel file, and refusing to uploading a .tar.gz distribution, but I would be interested to know the correct fix.
Edit: How does pip know not to download the wheel distribution if the Python/os/architecture is not matching? Does it just use the .whl filename convention or is there something more sophisticated than that happening behind the scenes? Can we somehow give the metadata to a source distribution to make pip do the right thing with .tar.gz uploads?
magicstack
is python3 only becausesetup.py
fails on python2.x, then it seems like one possible way to make this work is to force yoursetup.py
to fail on inappropriate python versions... – Limonsetup.py
. – Merrillsetup.py
check the Python version. – Wein