0

Let's say I have a setup.cfg (or setup.py) file with all the packages listed.

Now, if I run pip install . it'll install all packages and it's dependencies listed in install_requires. Is there a way to only get the list of packages and dependencies without downloading or installing them, like in a requirements.txt format?

This command I'm looking for ideally would also work for pip install '.[tests]', which would list packages defined for tests under extras_require in setup.cfg.

What this question is NOT asking:

  • I'm not asking for pip freeze or pip list type of command which lists all the packages installed in an environment. Rather I want the same type of list, just not of the packages already installed but of the packages that will be installed by the defined configuration in setup.cfg.
  • I'm not asking about how to generate this list by downloading these packages either, but only to collect them. I don't see why pip would need to download these packages when what I need is only the list of the packages and dependencies with their versions.

SOLUTION

stackoverflow marked this question as a duplicate which it is NOT. I have found a solution however because this question is closed I won't be able to submit it as an answer, but will post it here in the question instead.

To generate requirements.txt for packages listed in install_requires in your setup.cfg or setup.py, you would need to install pip-tools.

pip install pip-tools
pip-compile

To generate a requirements.txt file that includes packages specified under extras_requires for tests and dev:

pip-compile --extra tests --extra devrequirements.txt file with packages listed under
6
  • stackoverflow.com/…
    – phd
    Jul 22, 2021 at 19:56
  • This question is not a duplicate of either of the posted questions. The posted questions asks for listing packages without installing, whereas this question asks for without downloading or installing. Please reopen. Jul 23, 2021 at 0:28
  • 3
    How is pip supposed to know what the dependencies of a package are unless it downloads that package to inspect its metadata? Granted, there might be some cases where pypi can provide that information directly (though I'd need to read the fine source to see if it actually does so even in those cases), but there are 100%-absolute-certainty cases where it's impossible (f/e, cases where something depends on -e https://github.com/example/something@somehash, so the only way to find the dependency list is to do a git clone). Jul 23, 2021 at 0:51
  • @CharlesDuffy , I have posted the answer/solution to the question itself since I can't post an answer to this closed-question. Please review the Solution to answer your question, it should answer your question. Sep 16, 2021 at 21:51
  • @rrlamichhane pip-compile also downloads packages, so it doesn't answer your question. Run it with --verbose to see it downloading. As Charles Duffy already mentioned, it is not currently possible to get dependencies of a package without download.
    – wim
    Nov 6, 2021 at 22:45

0

Browse other questions tagged or ask your own question.