How can I specify library versions in setup.py?
Solution 1
I'm not sure about buildout, however, for setuptools/distribute, you specify version info with the comparison operators (like ==
, >=
, or <=
).
For example:
install_requires = ['django-pipeline==1.1.22', 'south>=0.7']
Solution 2
You can add them to your requirements.txt
file along with the version.
For example:
django-pipeline==1.1.22
south>=0.7
and then in your setup.py
import os
from setuptools import setup
with open('requirements.txt') as f:
required = f.read().splitlines()
setup(...
install_requires=required,
...)
Reading from the docs -
It is not considered best practice to use
install_requires
to pin dependencies to specific versions, or to specify sub-dependencies (i.e. dependencies of your dependencies). This is overly-restrictive, and prevents the user from gaining the benefit of dependency upgrades.
https://packaging.python.org/discussions/install-requires-vs-requirements/#id5
Naftuli Kay
Updated on September 03, 2021Comments
-
Naftuli Kay almost 3 years
In my
setup.py
file, I've specified a few libraries needed to run my project:setup( # ... install_requires = [ 'django-pipeline', 'south' ] )
How can I specify required versions of these libraries?
-
Tarsis Azevedo over 12 yearsto undestand the setup.py better read the docs
-
Adam Wagner over 12 yearsI know setup.py with distutils/setuptools/distribute, does buildout use this as well? I've never used it before, and wasn't sure why the OP mentioned buildout.
-
Martijn Pieters over 12 yearsBuildout honors the
install_requires
entry of packages, including version requirements. It uses setuptools under the hood for this. -
Naftuli Kay over 12 yearsNice, thanks, that answers my question. I forgot that Buildout used setuptools under the hood.
-
qed almost 10 yearsHow can I specify the version of python?
-
Dev Aggarwal almost 6 yearsDoes setup.py also honour the versions I have installed in my current env? Or does it just fetch the latest ones available?
-
tuomastik over 4 years@qed
python_requires='>=3',
More information -
Tianyi Shi about 3 years@TarsisAzevedo unfortunately the docs does not give these examples, as of April 2021. That page doesn’t even mention “ install_requires”
-
Eliav Louski over 2 yearswhat if I want to accept any patch (x.x.any) version?