I'm not sure this is possible. Google does not seem to have any answers.
Running Linux Debian can I list all pip packages and size (amount of disk space used) thats installed?
i.e. List all pip
packages with size on disk?
I'm not sure this is possible. Google does not seem to have any answers.
Running Linux Debian can I list all pip packages and size (amount of disk space used) thats installed?
i.e. List all pip
packages with size on disk?
Go to the package site to find the size e.g. https://pypi.python.org/pypi/pip/json
Could please try this one(A bit long though, maybe there are better solutions):
$ pip list | xargs pip show | grep -E 'Location:|Name:' | cut -d ' ' -f 2 | paste -d ' ' - - | awk '{print $2 "/" tolower($1)}' | xargs du -sh 2> /dev/null
the output should look like this:
80K /home/lord63/.pyenv/versions/2.7.11/envs/py2/lib/python2.7/site-packages/blinker
3.8M /home/lord63/.pyenv/versions/2.7.11/envs/py2/lib/python2.7/site-packages/docutils
296K /home/lord63/.pyenv/versions/2.7.11/envs/py2/lib/python2.7/site-packages/ecdsa
340K /home/lord63/.pyenv/versions/2.7.11/envs/py2/lib/python2.7/site-packages/execnet
564K /home/lord63/.pyenv/versions/2.7.11/envs/py2/lib/python2.7/site-packages/fabric
1.4M /home/lord63/.pyenv/versions/2.7.11/envs/py2/lib/python2.7/site-packages/flask
316K /home/lord63/.pyenv/versions/2.7.11/envs/py2/lib/python2.7/site-packages/httplib2
1.9M /home/lord63/.pyenv/versions/2.7.11/envs/py2/lib/python2.7/site-packages/jinja2
...
should works if the package is installed in Location/Name
. (location and name are from pip show <package>
)
pip show <package>
will show you the location:
---
Metadata-Version: 2.0
Name: Flask
Version: 0.10.1
Summary: A microframework based on Werkzeug, Jinja2 and good intentions
Home-page: http://github.com/mitsuhiko/flask/
Author: Armin Ronacher
Author-email: armin.ronacher@active-4.com
License: BSD
Location: /home/lord63/.pyenv/versions/2.7.11/envs/py2/lib/python2.7/site-packages
Requires: itsdangerous, Werkzeug, Jinja2
we get the Name
and Location
to join them to get the location, finally use du -sh
to get the package size.
New version for new pip list format:
pip2 list --format freeze|awk -F = {'print $1'}| xargs pip2 show | grep -E 'Location:|Name:' | cut -d ' ' -f 2 | paste -d ' ' - - | awk '{print $2 "/" tolower($1)}' | xargs du -sh 2> /dev/null|sort -h
History :
There is no command or applications developed for that purpose at the moment, we need to check that manually
Manual Method I :
du /usr/lib/python3.5/ --max-depth=2 | sort -h
du /usr/lib64/python3.5/ --max-depth=2 | sort -h
This does not include packages/files installed out of that directory, thus said we will get 95% with those 2 simples command
Also if you have other version of python installed, you need to adapt the directory
Manual Method II :
pip list | sed '/Package/d' | sed '/----/d' | sed -r 's/\S+//2' | xargs pip show | grep -E 'Location:|Name:' | cut -d ' ' -f 2 | paste -d ' ' - - | awk '{print $2 "/" $(find $2 -maxdepth 1 -iname $1)}' | xargs du -sh | sort -h
Search the install directory with the package name with case insensitive
Manual Method II Alternative I :
pip list | sed '/Package/d' | sed '/----/d' | sed -r 's/\S+//2' | xargs pip show | grep -E 'Location:|Name:' | cut -d ' ' -f 2 | paste -d ' ' - -| awk '{print $2 "/" tolower($1)}' | xargs du -sh | sort -h
Search the install directory with the package name with lowered case
Manual Method II Alternative II :
pip list | sed '/Package/d' | sed '/----/d' | sed -r 's/\S+//2' | xargs pip show | grep -E 'Location:|Name:' | cut -d ' ' -f 2 | paste -d ' ' - -| awk '{print $2 "/" $1}' | xargs du -sh | sort -h
Search the install directory with the package name
Note :
For methods using du
, output lines starting with du: cannot access
need to be checked manually;
The command use the install directory and add to it the name of the package but some times the package name and directory name are different...
Make it simple :
Modified above for pip version 18 and above:
pip list | tail -n +3 | awk '{print $1}' | xargs pip show | grep -E 'Location:|Name:' | cut -d ' ' -f 2 | paste -d ' ' - - | awk '{print $2 "/" tolower($1)}' | xargs du -sh 2> /dev/null | sort -hr
This command shows pip packages, sorted by descending order of sizes.
I followed below steps to calculate disk usage of all packages
du -h path/to/all/packages
Note - Insert any package name in place of some package e.g pandas
Bonus - find size of particular pip package
pip3 show "package_name" | grep "Location:"
this will return path/to/all/packages
du -h path/to/all/packages/package_name