Force python version in setup.py

We are currently installing \ installing some packages on the system, indicating their version and dependencies in the setup.py file in the install_requires attribute. Our system requires python 2.7. Sometimes users have several versions of python, say 2.6.x and 2.7, some packages that, he said, are already available, but actually are on the system available in the list of site packages 2.6. In addition, some users have only 2.6, how to force use setup.py, or is there any other way to say that it has only python 2.7, and all the packages that we want to install setup.py for updating are only 2.7. To run our code requires a minimum of 2.7 on the machine.

Thanks! Santhosh

+14
python setuptools
source share
2 answers

Since setup.py installed via pip (and pip itself is started by the python interpreter), it is not possible to specify which version of Python to use in setup.py .

Instead, look at this answer at setup.py: limit the valid version of the python interpreter which has a basic workaround to stop the installation.

In your case, the code will look like this:

 import sys if sys.version_info < (2,7): sys.exit('Sorry, Python < 2.7 is not supported') 
+11
source share

The current best practice ( python_requires from this article in March 2018) is to add the python_requires argument directly to the setup() call in setup.py :

 from setuptools import setup [...] setup(name="my_package_name", python_requires='>3.5.2', [...] 

Note that this requires setuptools> = 24.2.0 and pip> = 9.0.0; See the documentation for more information.

+43
source share

All Articles