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 tool
Adding to @Paul Woolcock's answer,
pip freeze > requirements.txt
will create a requirements file with all installed packages along with the installed version numbers in the active environment at the current location. Running
pip install -r requirements.txt
will install the packages specified in the requirements file.
pip freeze lists all installed packages even if not by pip/easy_install. On CentOs/Redhat a package installed through rpm is found.
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 https://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/Ubuntu method is dpkg -S
) and what is the "no package owns that path" return (Debian/Ubuntu is no path found matching pattern
). Debian/Ubuntu 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 2>&1 | grep 'no path found'
Fedora users can try (thanks @eddygeek):
find /usr/lib/python2.7/site-packages -maxdepth 2 -name __init__.py | xargs rpm -qf | grep 'not owned by any package'
Take note that if you have multiple versions of Python installed on your computer, you may have a few versions of pip associated with each.
Depending on your associations, you might need to be very cautious of what pip command you use:
pip3 list
Worked for me, where I'm running Python3.4. Simply using pip list
returned the error The program 'pip' is currently not installed. You can install it by typing: sudo apt-get install python-pip
.
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:'
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: https://pip.pypa.io/en/latest/reference/pip_list/