Python setup config install_requires "good practices"
Question:
My question here may seem really naive but I never found any clue about it on web resources.
The question is, concerning install_requires
argument for setup()
function or setup.cfg
file, is it a good practice to mention every package used, even python built-in ones such as os
for example ?
One can assume that any python environment has those common packages, so is it problematic to explicitly mention them in the setup, making it potentially over-verbose ?
Thanks
Answers:
install_requires
should include non-standard library requirements, and constraints on their versions (as needed).
For example, this would declare minimal versions for numpy
and scipy
, but allow any version of scikit-learn
:
setup(
# ...
install_requires=["numpy>=1.13.3", "scipy>=0.19.1", "scikit-learn"]
)
Packages such as os
, sys
are part of Python’s standard library, so should not be included.
- As @sinoroc mentioned, only direct 3rd party dependencies should be declared here. Dependencies-of-your-dependencies are handled automatically. (For example,
scikit-learn
depends on joblib
; when the former is required, the latter will be installed).
- A list of standard library packages are listed here: https://docs.python.org/3/library/
I’ve found it helpful to read other packages and see how their setup.py
files are defined.
install_requires
should mention only packages that don’t come prepackaged with the standard library.
If you’re afraid some package might not be included due to Python versioning, you can specify that your packages requires a python version bigger or equal to X.
Note: That packaging python packages is a notoriously hairy thing.
I’d recommend you take a look at pyproject.toml, these can be pip installed like any normal package and are used by some of the more modern tools like poetry
You should list top-level 3rd party dependencies.
-
Don’t list packages and modules from Python’s standard library.
-
Do list 3rd party dependencies your code directly depends on, i.e. the projects containing:
- the packages and modules your code imports;
- the binaries your code directly calls (in subprocesses for example).
-
Don’t list dependencies of your dependencies.
My question here may seem really naive but I never found any clue about it on web resources.
The question is, concerning install_requires
argument for setup()
function or setup.cfg
file, is it a good practice to mention every package used, even python built-in ones such as os
for example ?
One can assume that any python environment has those common packages, so is it problematic to explicitly mention them in the setup, making it potentially over-verbose ?
Thanks
install_requires
should include non-standard library requirements, and constraints on their versions (as needed).
For example, this would declare minimal versions for numpy
and scipy
, but allow any version of scikit-learn
:
setup(
# ...
install_requires=["numpy>=1.13.3", "scipy>=0.19.1", "scikit-learn"]
)
Packages such as os
, sys
are part of Python’s standard library, so should not be included.
- As @sinoroc mentioned, only direct 3rd party dependencies should be declared here. Dependencies-of-your-dependencies are handled automatically. (For example,
scikit-learn
depends onjoblib
; when the former is required, the latter will be installed). - A list of standard library packages are listed here: https://docs.python.org/3/library/
I’ve found it helpful to read other packages and see how their setup.py
files are defined.
install_requires
should mention only packages that don’t come prepackaged with the standard library.
If you’re afraid some package might not be included due to Python versioning, you can specify that your packages requires a python version bigger or equal to X.
Note: That packaging python packages is a notoriously hairy thing.
I’d recommend you take a look at pyproject.toml, these can be pip installed like any normal package and are used by some of the more modern tools like poetry
You should list top-level 3rd party dependencies.
-
Don’t list packages and modules from Python’s standard library.
-
Do list 3rd party dependencies your code directly depends on, i.e. the projects containing:
- the packages and modules your code imports;
- the binaries your code directly calls (in subprocesses for example).
-
Don’t list dependencies of your dependencies.