Can pip install from setup.cfg, as if installing from a requirements file?

Question:

According to the setuptools documentation, setuptools version 30.3.0 (December 8, 2016) “allows using configuration files (usually setup.cfg) to define package’s metadata and other options which are normally supplied to setup() function”. Similar to running pip install -r requirements.txt to install Python packages from a requirements file, is there a way to ask pip to install the packages listed in the install_requires option of a setup.cfg configuration file?

Asked By: argentpepper

||

Answers:

No, pip does not currently have facilities for parsing requirements from setup.cfg. It will only install dependencies along with the main package(s) provided in setup.py.

Answered By: rnorris

Here is my workaround. I use the following command to parse the install_requires element from the setup.cfg file and install the packages using pip.

python3 -c "import configparser; c = configparser.ConfigParser(); c.read('setup.cfg'); print(c['options']['install_requires'])" | xargs pip install

Here is a more readable version of the Python script before the pipe in the above command line.

import configparser
c = configparser.ConfigParser()
c.read('setup.cfg')
print(c['options']['install_requires'])
Answered By: argentpepper

If you have all your dependencies and other metadata defined in setup.cfg, just create a minimal setup.py file in the same directory that looks like this:

from setuptools import setup
setup()

From now on you can run pip install and it will install all the dependencies defined in setup.cfg as if they were declared in setup.py.

Answered By: Jakub Kukul

If your setup.cfg belongs to a well-formed package, you can do e.g.:

pip install -e .[tests,dev]

(install this package in place, with given extras)

afterwards you can pip uninstall that package by name, leaving deps in place.

Answered By: Dima Tisnek
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.