How to See Pip Package Sizes Installed

How to see pip package sizes installed?

Go to the package site to find the size e.g. https://pypi.python.org/pypi/pip/json

Then expand releases, find the version, and look up the size (in bytes).

How to know size of python module?

import os
import pip

def calc_container(path):
total_size = 0
for dirpath, dirnames, filenames in os.walk(path):
for f in filenames:
fp = os.path.join(dirpath, f)
total_size += os.path.getsize(fp)
return total_size

for dist in pip.get_installed_distributions():
try:
path = os.path.join(dist.location, dist.project_name)
size = calc_container(path)
if size:
print path
print size
except OSError:
'{} no longer exists'.format(dist.project_name)

If you're in virtualenv, you can use first option to get more:

get_installed_distributions(local_only=True, skip=('python', 'wsgiref', 'argparse'), include_editables=True, editables_only=False, user_only=False)
Return a list of installed Distribution objects.

If local_only is True (default), only return installations
local to the current virtualenv, if in a virtualenv.

Where does pip install its packages?

pip when used with virtualenv will generally install packages in the path <virtualenv_name>/lib/<python_ver>/site-packages.

For example, I created a test virtualenv named venv_test with Python 2.7, and the django folder is in venv_test/lib/python2.7/site-packages/django.

Listing the dependencies of a package using pip

Note that this answer from 2012 is out of date. First, the workaround, which the answer already said you probably shouldn't do in 2012, now you can't do it. If you want a similar workaround, you could use pip download, but it's even less likely to be what you want. Especially since pip show has been improved. Fortunately, the question has been marked as a dup of a later question, so there's no reason to read this answer except for historical purposes.


You can't, at least not directly.

You can import the pip module in your own code and download the requirements file and then iterate through it. Or, from the command line, you can pip install --no-install --verbose.

But really, unless this is something you need to automate, it's probably easier to just go to http://pypi.python.org/ and search for the package there instead of using pip.

How can I see what packages were installed using `sudo pip install`?

any modules you installed with sudo will be owned by root, so you can open your shell/terminal, cd to site-packages directory & check the directories owner with ls -la, then any that has root in the owner column is the one you want to uninstall.

Python and pip, list all versions of a package that's available?

(update: As of March 2020, many people have reported that yolk, installed via pip install yolk3k, only returns latest version. Chris's answer seems to have the most upvotes and worked for me)

The script at pastebin does work. However it's not very convenient if you're working with multiple environments/hosts because you will have to copy/create it every time.

A better all-around solution would be to use yolk3k, which is available to install with pip. E.g. to see what versions of Django are available:

$ pip install yolk3k
$ yolk -V django
Django 1.3
Django 1.2.5
Django 1.2.4
Django 1.2.3
Django 1.2.2
Django 1.2.1
Django 1.2
Django 1.1.4
Django 1.1.3
Django 1.1.2
Django 1.0.4

yolk3k is a fork of the original yolk which ceased development in 2012. Though yolk is no longer maintained (as indicated in comments below), yolk3k appears to be and supports Python 3.

Note: I am not involved in the development of yolk3k. If something doesn't seem to work as it should, leaving a comment here should not make much difference. Use the yolk3k issue tracker instead and consider submitting a fix, if possible.

Conda command to list size of packages

Mine the conda-meta

One way to get at this is by mining the JSON metadata files for each package inside an environment's conda-meta/ directory. There are two types of sizes listed:

  • size - total zipped tarball size for the package
  • size_in_bytes - individual unzipped file sizes within a package

Since you seem interested in total size of a package, let's do the simpler size. This will let us get a quick ranking of packages by their download size.

Commands

## activate the environment of interest
conda activate foo

## search all the JSONs for '"size":'
grep '"size":' ${CONDA_PREFIX}/conda-meta/*.json |\

## sort result
sort -k3rn |\

## show only filename
sed 's/.*conda-meta\///g' |\

## print with columns
column -t

Example Output

jaxlib-0.1.67-py39h6e9494a_0.json:          "size":  38576847,
scipy-1.6.3-py39h056f1c0_0.json: "size": 19495906,
python-3.9.4-h9133fd0_0_cpython.json: "size": 13160553,
libopenblas-0.3.15-openmp_h5e1b9a4_1.json: "size": 9163719,
numpy-1.20.3-py39h7eed0ac_1.json: "size": 5732039,
tk-8.6.10-hb0a8c7a_1.json: "size": 3420669,
openssl-1.1.1k-h0d85af4_0.json: "size": 1985060,
sqlite-3.35.5-h44b9ce1_0.json: "size": 1810221,
libgfortran5-9.3.0-h6c81a4c_22.json: "size": 1766473,
pip-21.1.2-pyhd8ed1ab_0.json: "size": 1147500,
libcxx-11.1.0-habf9029_0.json: "size": 1055976,
setuptools-49.6.0-py39h6e9494a_3.json: "size": 972968,
ncurses-6.2-h2e338ed_4.json: "size": 901840,
jax-0.2.14-pyhd8ed1ab_0.json: "size": 571585,
llvm-openmp-11.1.0-hda6cdc1_1.json: "size": 274368,
readline-8.1-h05e3726_0.json: "size": 272444,
xz-5.2.5-haf1e3a3_1.json: "size": 233058,
certifi-2021.5.30-py39h6e9494a_0.json: "size": 144599,
ca-certificates-2021.5.30-h033912b_0.json: "size": 139088,
tzdata-2021a-he74cb21_0.json: "size": 123802,
zlib-1.2.11-h7795811_1010.json: "size": 104180,
absl-py-0.12.0-pyhd8ed1ab_0.json: "size": 98565,
tqdm-4.61.0-pyhd8ed1ab_0.json: "size": 81513,
opt_einsum-3.3.0-pyhd8ed1ab_1.json: "size": 54494,
libffi-3.3-h046ec9c_2.json: "size": 46425,
wheel-0.36.2-pyhd3deb0d_0.json: "size": 31381,
python-flatbuffers-2.0-pyhd8ed1ab_0.json: "size": 28606,
libgfortran-5.0.0-9_3_0_h6c81a4c_22.json: "size": 19280,
six-1.16.0-pyh6c4a22f_0.json: "size": 14259,
libblas-3.9.0-9_openblas.json: "size": 11762,
libcblas-3.9.0-9_openblas.json: "size": 11671,
liblapack-3.9.0-9_openblas.json: "size": 11671,
python_abi-3.9-1_cp39.json: "size": 3921,

The above output shows jaxlib is the largest package, followed by scipy, then the python interpreter itself. In this case, if I wanted to remove jaxlib it would also entail removing jax.

Notes

I think the above serves as a first approximation for ranking the packages by size. The size_in_bytes could possibly be more exact, but to be thorough one would need to also consider which individual files are hardlinked, since those actually shouldn't be counted against the package on a per environment level. For them, there is only one copy per system and it gets reused across environments.

How do I search for an available Python package using pip?

To search for a package, issue the command

pip search [package-name]


Related Topics



Leave a reply



Submit