Reputation: 91620
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?
Upvotes: 117
Views: 73165
Reputation: 15560
install_requires=[
#-- the `~` range is supported:
'py-consul ~= 1.5', # means >=1.5.0, <1.6
#-- the `^` range is not supported, emulate:
'requests >=2.10, <3.0',
],
Spec: https://packaging.python.org/en/latest/specifications/version-specifiers/#id5
Quick reminder:
In install_requires
(setup_requires
, tests_require
), package authors declare the widest acceptable range of their dependencies' versions. That's to provide maximum reasonable flexibility to downstream package consumers in their dependencies.
In requirements.txt
, you should always keep completely pinned install plan, as if from pip freeze
. That's to ensure reproducible build (similar to lockfiles in packaging systems of other languages).
Upvotes: 0
Reputation: 16097
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']
See the Python packaging documentation
Upvotes: 173
Reputation: 20011
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
Upvotes: 9