How can I specify library versions in setup.py?

47,671

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

Share:
47,671
Naftuli Kay
Author by

Naftuli Kay

Updated on September 03, 2021

Comments

  • Naftuli Kay
    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
    Tarsis Azevedo over 12 years
    to undestand the setup.py better read the docs
  • Adam Wagner
    Adam Wagner over 12 years
    I 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
    Martijn Pieters over 12 years
    Buildout honors the install_requires entry of packages, including version requirements. It uses setuptools under the hood for this.
  • Naftuli Kay
    Naftuli Kay over 12 years
    Nice, thanks, that answers my question. I forgot that Buildout used setuptools under the hood.
  • qed
    qed almost 10 years
    How can I specify the version of python?
  • Dev Aggarwal
    Dev Aggarwal almost 6 years
    Does setup.py also honour the versions I have installed in my current env? Or does it just fetch the latest ones available?
  • tuomastik
    tuomastik over 4 years
    @qed python_requires='>=3', More information
  • Tianyi Shi
    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
    Eliav Louski over 2 years
    what if I want to accept any patch (x.x.any) version?