I have a module that works both on python 2 and python 3. In Python<3.2 I would like to install a specific package as a dependency. For Python>=3.2.
Something like:
install_requires=[ "threadpool >= 1.2.7 if python_version < 3.2.0", ],
How can one make that?
install_requires is a section within the setup.py file in which you need to input a list of the minimum dependencies needed for a project to run correctly on the target operating system (such as ubuntu). When pip runs setup.py, it will install all of the dependencies listed in install_requires.
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.
If your package is developed only by yourself (i.e. on a single machine) but you are planning to redistribute it, then setup.py / setup. cfg should be enough. If you package is developed on multiple machines and you also need to redistribute it, you will need both the requirements. txt and setup.py / setup.
The short answer is that requirements. txt is for listing package requirements only. setup.py on the other hand is more like an installation script. If you don't plan on installing the python code, typically you would only need requirements.
Use environment markers:
install_requires=[ 'threadpool >= 1.2.7; python_version < "3.2.0"', ]
Setuptools specific usage is detailed in their documentation. The syntax shown above requires setuptools v36.2+ (change log).
This has been discussed here, it would appear the recommend way is to test for the Python version inside your setup.py
using sys.version_info
;
import sys if sys.version_info >= (3,2): install_requires = ["threadpool >= 1.2.7"] else: install_requires = ["threadpool >= 1.2.3"] setup(..., install_requires=install_requires)
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