Take the 2-minute tour ×

Is there a way to find all Python PyPI packages that were installed with easy_install or pip? I mean, excluding everything that was/is installed with the distributions tools (in this case apt-get on Debian).

share|improve this question
Related: Listing installed python site-packages? –  Piotr Dobrogost Nov 12 '11 at 18:32
Stallion –  Tarantula Feb 8 '12 at 15:22
add comment

8 Answers

pip freeze will output a list of installed packages and their versions. It also allows you to write those packages to a file that can later be used to set up a new environment.


share|improve this answer
Why on earth can't they just use list like every other Unix app does? facepalm –  mikemaccana Feb 13 '13 at 17:33
As of Version 1.3 'pip list' has been added. See my answer below and the docs here: pip-installer.org/en/latest/usage.html#pip-list –  knitatoms May 26 '13 at 12:13
add comment

As of version 1.3 of pip you can now use pip list

It has some useful options including the ability to show outdated packages. Here's the documentation: http://www.pip-installer.org/en/latest/usage.html#pip-list

share|improve this answer
add comment

If Debian behaves like recent Ubuntu versions regarding pip install default target, it's dead easy: it installs to /usr/local/lib/ instead of /usr/lib (apt default target). Check http://askubuntu.com/questions/173323/how-do-i-detect-and-remove-python-packages-installed-via-pip/259747#259747

I am an ArchLinux user and as I experimented with pip I met this same problem. Here's how I solved it in Arch.

find /usr/lib/python2.7/site-packages -maxdepth 2 -name __init__.py | xargs pacman -Qo | grep 'No package'

Key here is /usr/lib/python2.7/site-packages, which is the directory pip installs to, YMMV. pacman -Qo is how Arch's pac kage man ager checks for ownership of the file. No package is part of the return it gives when no package owns the file: error: No package owns $FILENAME. Tricky workaround: I'm querying about __init__.py because pacman -Qo is a little bit ignorant when it comes to directories :(

In order to do it for other distros, you have to find out where pip installs stuff (just sudo pip install something), how to query ownership of a file (Debian method is dpkg -S) and what is the "no package owns that path" return (Debian is no path found matching pattern). Debian users, beware: dpkg -S will fail if you give it a symbolic link. Just resolve it first by using realpath. Like this:

find /usr/local/lib/python2.7/dist-packages -maxdepth 2 -name __init__.py | xargs realpath | xargs dpkg -S | grep 'no path found'
share|improve this answer
+1 Thanks alot for the Arch one-liner, that's exactly what I was looking for. By the way, curious fact: my Arch installation is localized in italian, but grep correctly 'grepped' the lines that said 'Nessun pacchetto' (italian for 'No package') even though I grepped for 'No package'. How come? –  Nadir Sampaoli Apr 17 '13 at 6:09
@NadirSampaoli Awesome grep is awesome. –  barraponto Apr 18 '13 at 15:46
add comment

The below is a little slow, but it gives a nicely formatted list of packages that pip is aware of. That is to say, not all of them were installed "by" pip, but all of them should be able to be upgraded by pip.

$ pip search . | egrep -B1 'INSTALLED|LATEST'

The reason it is slow is that it lists the contents of the entire pypi repo. I filed a ticket suggesting pip --list provide similar similar but more efficiently.

Sample output: (restricted the search to a subset instead of '.' for all.)

$ pip search selenium | egrep -B1 'INSTALLED|LATEST'

selenium                  - Python bindings for Selenium
  INSTALLED: 2.24.0
  LATEST:    2.25.0
robotframework-selenium2library - Web testing library for Robot Framework
  INSTALLED: 1.0.1 (latest)
share|improve this answer
Why not file the ticket yourself? –  lajarre Feb 6 '13 at 16:57
Apparentlly the next version of pip will have a new list command: pip-installer.org/en/latest/usage.html#pip-list –  MarkHu Feb 7 '13 at 21:51
add comment

Get all file/folder names in site-packages/ (and dist-packages/ if it exists), and use your package manager to strip the ones that were installed via package.

share|improve this answer
add comment

pip freeze lists all installed packages even if not by pip/easy_install. On CentOs/Redhat a package installed through rpm is found.

share|improve this answer
add comment

pip.get_installed_distributions() will give a list of installed packages

import pip
from os.path import join

for package in pip.get_installed_distributions():
    print(package.location) # you can exclude packages that's in /usr/XXX
    print(join(package.location, package._get_metadata("top_level.txt"))) # root directory of this package
share|improve this answer
add comment

Here is the one-liner for fedora or other rpm distros (based on @barraponto tips):

find /usr/lib/python2.7/site-packages -maxdepth 2 -name __init__.py | xargs rpm -qf | grep 'not owned by any package'

Append this to the previous command to get cleaner output:

 | sed -r 's:.*/(\w+)/__.*:\1:'
share|improve this answer
add comment

Your Answer


