Created
January 10, 2018 20:36
-
-
Save orendon/292a2f3abbb7fa85197f62677de7428e to your computer and use it in GitHub Desktop.
Python: list pip packages size
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
It'd probably be safer to use one of the other list formats which are intended to be machine-parseable:
pip list --format json | jq -r '.[]|.name' | xargs pip show...
or
pip list --format freeze | cut -d= -f1 | xargs pip show...
Personally, I'd just do this as the entire solution, if I was on a system with GNU awk (so a Mac user or Solaris or whatever might need to use gawk instead of awk; I forget if tolower
is standard awk or a GNU extension):
pip list --format freeze | cut -d= -f1 | \
while read P; do du -hs $( pip show $P | awk -v p="$P" '/Location/{print $2"/"tolower(p)}' ); done
That gives this output on a python 3.9 container with pygments installed. It still fails for some eggs, but gets you close.
13M /usr/local/lib/python3.9/site-packages/pip
7.9M /usr/local/lib/python3.9/site-packages/pygments
2.3M /usr/local/lib/python3.9/site-packages/setuptools
264K /usr/local/lib/python3.9/site-packages/wheel
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://notes.shanakadesoysa.com/Python/Basics/pip_package_size/
This works on Mac with
gawk
installed