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
rrlamichhane
  • 1,435
  • 2
  • 18
  • 34
  • https://stackoverflow.com/search?q=%5Bpip%5D+list+dependencies+without+installation – phd Jul 22 '21 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. – rrlamichhane Jul 23 '21 at 00: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). – Charles Duffy Jul 23 '21 at 00: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. – rrlamichhane Sep 16 '21 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 06 '21 at 22:45
  • @wim I honestly don't care if packages are downloaded and resolved automatically in the background; that satisfies my requirement. I just don't want to be allocating folders, installing packages, and other shenanigans to generate this list. – rrlamichhane Nov 08 '21 at 20:29

0 Answers0