Search code examples
pythonpipsetuptoolssetup.pypyproject.toml

Install specific version of setuptools as a dependency of package


My package has setuptools in dependencies. I am trying to restrict the version of setuptools when installing my package. The package has following restriction in setup.py:

setup(
    setup_requires=[
        'setuptools==50.2.0',
        'pip>=19,!=20.0,!=20.0.1,<21'
        ],
...

And it has the same restriction in pyproject.toml:

[build-system]
requires = ["setuptools==50.2.0", "pip>=19,!=20.0,!=20.0.1,<21", "wheel"]  # PEP 508 specifications.

However, when installing my package with pip, it downloads the latest setuptools 50.3.0.

Why does it ignore the requirements? How can I make it not install the latest version?


Solution

  • Thanks to the answers and comments I can make a conclusion.

    To use a specific version of setuptools it is necessary to have it in both locations - in pyproject.toml and at the beginning of install_requires of setup.py.

    The tool like pip will use the version from pyproject.toml to build the project. However, if there is any dependency that has the latest version of setuptools in its requirements, then the latest version will be used to install the dependency. Also, the environment will keep the version that was last installed.