Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 250
mmnormyle Avatar asked May 16 '18 22:05

mmnormyle


People also ask

How do I find the dependencies of a Python package?

Pip Check Command – Check Python Dependencies After Installation. Because pip doesn't currently address dependency issues on installation, the pip check command option can be used to verify that dependencies have been installed properly in your project. For example: $ pip check No broken requirements found.

What is a mirror package PyPI?

pypi-mirror is a small script to generate a partial PyPI mirror. It relies on pip to do the most difficult part of the job (downloading a package and its dependencies).

What is Yank in PyPI?

A yanked release is a release that is always ignored by an installer, unless it is the only release that matches a version specifier (using either == or === ).


2 Answers

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'])
like image 104
makunha Avatar answered Sep 30 '22 07:09

makunha


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.

like image 30
djcrabhat Avatar answered Sep 29 '22 07:09

djcrabhat