Get the requirements of a package in PyPI without installing it? [duplicate]
Asked Answered
G

2

9

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!

Grekin answered 16/5, 2018 at 22:39 Comment(0)
P
13
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'])
Progressist answered 16/5, 2018 at 22:44 Comment(2)
curl -L 'https://pypi.python.org/pypi/tensorflow/json' | jq '.info.requires_dist'Carboloy
@Carboloy You should add that as an answer since comments can and may get accidentally get purged by mods sometimes. Thanks.Sexy
U
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.

Uxoricide answered 16/5, 2018 at 22:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.