List dependencies of Python wheel file
As previously mentioned, .whl
files are just ZIP archives. You can just open them and poke around in the METADATA
file.
There is a tool, however, that can make this manual process a bit easier. You can use pkginfo, which can be installed with pip.
CLI usage:
$ pip install pkginfo$ pkginfo -f requires_dist psutil-5.4.5-cp27-none-win32.whlrequires_dist: ["enum34; extra == 'enum'"]
API usage:
>>> import pkginfo>>> wheel_fname = "psutil-5.4.5-cp27-none-win32.whl">>> metadata = pkginfo.get_metadata(wheel_fname)>>> metadata.requires_dist[u"enum34 ; extra == 'enum'"]
I just tried to unzip (not gunzip) a wheel package I had lying around. The packagename-version.dist-info/METADATA
file contains a list of Requires-Dist:
entries that contain the compiled requirements from setup.py
.
Here's a minimal snippet that doesn't require you to have any external tool (unzip, gzip or similars), so it should work in both *nix/windows:
wheeldeps.py:
import argparsefrom zipfile import ZipFileparser = argparse.ArgumentParser()parser.add_argument('filename')args = parser.parse_args()archive = ZipFile(args.filename)for f in archive.namelist(): if f.endswith("METADATA"): for l in archive.open(f).read().decode("utf-8").split("\n"): if 'requires-dist' in l.lower(): print(l)
Example:
> python wheeldeps.py psutil-5.4.5-cp27-cp27m-win_amd64.whlRequires-Dist: enum34; extra == 'enum'