Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enforcing python version in setup.py

Currently, we are setting\installing up some packages on system by mentioning their version and dependencies in setup.py under install_requires attribute. Our system requires Python 2.7. Sometimes, users are having multiple versions of Python on their systems, say 2.6.x and 2.7, some packages it says are available already but actually on the system available under 2.6 site packages list. Also some users have 2.6 only, how to enforce from setup.py or is there any other way to say to have only Python 2.7 and all packages which we want setup.py to update are for only 2.7. We require minimum 2.7 on the machine to run our code.

Thanks! Santhosh

like image 985
Santhosh Avatar asked Oct 23 '13 06:10

Santhosh


People also ask

How do I set python version in setup py?

As the setup.py file is installed via pip (and pip itself is run by the python interpreter) it is not possible to specify which Python version to use in the setup.py file.

Is setup py outdated?

py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools. I found a very detailed write-up explaining this issue: "Why you shouldn't invoke setup.py directly" (October 2021).

What is __ version __ in python?

It provides a __version__ attribute. It provides the standard metadata version. Therefore it will be detected by pkg_resources or other tools that parse the package metadata (EGG-INFO and/or PKG-INFO, PEP 0345).

How do I run python3 setup py?

To install a package that includes a setup.py file, open a command or terminal window and: cd into the root directory where setup.py is located. Enter: python setup.py install.


2 Answers

The current best practice (as of this writing in March 2018) is to add a 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.

like image 194
Aaron V Avatar answered Oct 08 '22 03:10

Aaron V


As the setup.py file is installed via pip (and pip itself is run by the python interpreter) it is not possible to specify which Python version to use in the setup.py file.

Instead have a look at this answer to setup.py: restrict the allowable version of the python interpreter which has a basic workaround to stop the install.

In your case the code would be:

import sys if sys.version_info < (2,7):     sys.exit('Sorry, Python < 2.7 is not supported') 
like image 24
Ewan Avatar answered Oct 08 '22 03:10

Ewan