-1

How to list in Python project all libraries and their version?
(similar to Java maven pom.xml and Node.js npm 'package.json')

There is definitely way to specify that on command line,
e.g. pip install pandas==0.23, but that only hopefully will be listed in README, but most likely be forgotten.

Also as there is pip and conda, do they address this? Or maybe some other 3rd tool tries to unify for whatever pip or conda usage?

Paul Verest
  • 60,022
  • 51
  • 208
  • 332
  • Do you want something more than `pip list` or `conda list`? – tomjn Jun 03 '21 at 11:08
  • Depending on what exactly you need to do, ``requirements.txt``, ``setup.py`` or ``pyproject.toml`` should apply. Do you have a proper python package (which can be ``pip``-installed) and want to set its dependencies? Do you have a collection of python code and want to make the dependencies installable in one go? – MisterMiyagi Jun 03 '21 at 11:08
  • Are requirements.txt, setup.py or pyproject.toml 3 different option/tools? Please add answer with some direct links. I am coming from Java, and in Java it is common to specify exact dependencies, so other developers can join development any install quickly all required dependencies (libraries) automatically. But in Python it seem brittle. – Paul Verest Jun 03 '21 at 11:53

1 Answers1

1

There are two main mechanisms to specify libraries for a package/repository:

  • For an out-of-the-box package that can be installed with all dependencies, use setup.py/pyproject.toml. These are used by package managers to automatically install required dependencies on package installation.
  • For a reproducible installation of a given setup of possibly many packages, use requirements.txt. These are used by package managers to explicitly install required dependencies.

Notably, the two handle different use-cases: Package dependencies define the general dependencies, only restricting dependency versions to specific ranges when needed for compatibility. Requirements define the precise dependencies, restricting all direct and indirect dependency versions to replicate some pre-existing setup.

MisterMiyagi
  • 44,374
  • 10
  • 104
  • 119