8

I need something like the following:

pip showrequirements tensorflow

This would return something that allows me to parse the names of the required packages and the required versions:

astor>0.6, tensorboard>1.0.11, etc.

pip is getting this information in some form during the install and download command. I can see where it's happening in the code... but before I hack my way to using pip's internal code, is there any easy API or existing library that can do this?

edit: I cannot install the package to see this, so pip show won't work. One (hacky) solution is parsing the output of pip download.

Thanks!

mmnormyle
  • 763
  • 1
  • 8
  • 18

2 Answers2

9
pip show <package_name>

will list the dependencies in the "Requires" section. See documentation.

Edit:

pip show only works for installed packages. For uninstalled packages, PyPI has a JSON API.

For example:

import json

import requests

package_name = 'tensorflow'
url = 'https://pypi.python.org/pypi/' + str(package_name) + '/json'
data = requests.get(url).json()

print(data['info']['requires_dist'])
ndmeiri
  • 4,979
  • 12
  • 37
  • 45
makunha
  • 411
  • 3
  • 6
1

So there used to be a --no-install flag in older version of pip, but no longer. pip show will show you the "Requires" property, but only for packages installed in your environment (system or in your venv), where it seems you wanna check out requirements before you install. So, sadly, I think there's not a nice way to accomplish what you're looking for.

djcrabhat
  • 464
  • 5
  • 10