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).
-
Related: [Listing installed python site-packages?](http://stackoverflow.com/questions/2300794/) – Piotr Dobrogost Nov 12 '11 at 18:32
19 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.
https://pip.pypa.io/en/stable/reference/pip_freeze/#pip-freeze

- 2,396
- 1
- 17
- 31
-
92As of Version 1.3 'pip list' has been added. See my answer below and the docs here: http://www.pip-installer.org/en/latest/usage.html#pip-list – keybits May 26 '13 at 12:13
-
7list and freeze output different formats (as of the time of writing). The freeze output can be used to recreate environments: http://docs.python-guide.org/en/latest/dev/virtualenvs/#other-notes – Tom Saleeba Feb 19 '16 at 01:47
-
22`pip freeze` and `pip list` list everything. They don't exclude the packages that weren't installed by `pip`. – Eliad Dec 15 '16 at 00:15
-
I also find `pip freeze` to be reliable in scripts, whereas `pip list` will generate unexpected errors when being used with pipes. – Dale C. Anderson Jan 18 '17 at 19:54
-
3The new (?) `pip list -l` or `pip list --local` is the best answer, see http://stackoverflow.com/a/43012269/491884 by @MJB – jmuc May 02 '17 at 09:48
-
This does not responds the question: list packages installed by PIP but NOT the installed with the distro packages – Luis Vazquez May 08 '20 at 02:28
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/

- 3,966
- 4
- 37
- 59

- 4,383
- 2
- 20
- 18
-
4On Gentoo, this lists *all* the packages, even those installed by other means than pip. Does this really exclude non-pip installed modules on other system as requested by the question? – jlh Apr 14 '17 at 13:19
-
-
4`pip list --user` only shows packages installed by the user, and excludes system-wide packages. – Jacob Hume Mar 06 '20 at 18:57
-
@JacobHume the `--user` flag makes pip install stuff to the user install directory. it will not list stuff installed with `sudo pip install packagexyz`. – Capi Etheriel Aug 21 '21 at 13:46
If anyone is wondering you can use the 'pip show' command.
pip show [options] <package>
This will list the install directory of the given package.

- 1,802
- 1
- 12
- 17
Start with:
$ pip list
To list all packages. Once you found the package you want, use:
$ pip show <package-name>
This will show you details about this package, including its folder. You can skip the first part if you already know the package name
Click here for more information on pip show and here for more information on pip list.
Example:
$ pip show jupyter
Name: jupyter
Version: 1.0.0
Summary: Jupyter metapackage. Install all the Jupyter components in one go.
Home-page: http://jupyter.org
Author: Jupyter Development Team
Author-email: jupyter@googlegroups.org
License: BSD
Location: /usr/local/lib/python2.7/site-packages
Requires: ipywidgets, nbconvert, notebook, jupyter-console, qtconsole, ipykernel

- 1,660
- 1
- 15
- 19
-
Best answer IMHO. Really simple and fast if I know the package name. pip list is not even necessary and freeze can take a long time and I have to filter out stuff I don't care about. Simple: pip show my_packge – ChuckZ Aug 21 '18 at 22:16
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'

- 3,542
- 28
- 49
-
3+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 06:09
-
1@barraponto @NadirSampaoli grep does nothing in my case. Because grep try to grep in stdout, but `dpkg` write the error to stderr so i have to add a redirect `2>&1`. And for international output add `LANG= ` in front of `xargs dpkg -s`. and `sed` is also a nice tool ;) to keep only the package name of the path. So I end up with: `find /usr/local/lib/python2.7/dist-packages -maxdepth 2 -name __init__.py | xargs realpath | LANG= xargs dpkg -S 2>&1 | grep 'no path found' | sed "s/.*\/\([^\/]*\)\/__init__\.py.*/\1/"` – David Boho Nov 13 '15 at 13:23
-
1hi, I downvoted this by mistake and only just realised it, and now my vote's locked in. Could someone vote this up to neutralise my downvote? Thanks – Jonathan Oct 02 '16 at 14:14
Newer versions of pip have the ability to do what the OP wants via pip list -l
or pip freeze -l
(--list
).
On Debian (at least) the man page doesn't make this clear, and I only discovered it - under the assumption that the feature must exist - with pip list --help
.
There are recent comments that suggest this feature is not obvious in either the documentation or the existing answers (although hinted at by some), so I thought I should post. I would have preferred to do so as a comment, but I don't have the reputation points.
-
1turns out we had `pip freeze --local` for 8 years. `pip list --local` is available too... but notice the OP question is not about virtual environments (which `--local` supports) but about discerning distro packages from `sudo pip install` packages. – Capi Etheriel Jul 02 '17 at 07:33
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

- 5,795
- 6
- 39
- 61
-
2This will not work anymore. See https://github.com/pypa/pip/issues/5243 Instead you should use: import pkg_resources [print(d.project_name) for d in pkg_resources.working_set] – Almenon Jul 14 '18 at 23:14
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 functionality 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)
$

- 1,694
- 16
- 29
-
1
-
1Apparentlly the next version of pip will have a new list command: http://www.pip-installer.org/en/latest/usage.html#pip-list – MarkHu Feb 07 '13 at 21:51
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.

- 24,861
- 16
- 87
- 111
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
.

- 1,247
- 1
- 13
- 18
As @almenon pointed out, this no longer works and it is not the supported way to get package information in your code. The following raises an exception:
import pip
installed_packages = dict([(package.project_name, package.version)
for package in pip.get_installed_distributions()])
To accomplish this, you can import pkg_resources
. Here's an example:
import pkg_resources
installed_packages = dict([(package.project_name, package.version)
for package in pkg_resources.working_set])
I'm on v3.6.5

- 1,382
- 14
- 22
pip freeze lists all installed packages even if not by pip/easy_install. On CentOs/Redhat a package installed through rpm is found.

- 31
- 1
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:'

- 4,236
- 3
- 25
- 32
If you use the Anaconda python distribution, you can use the conda list
command to see what was installed by what method:
user@pc:~ $ conda list
# packages in environment at /anaconda3:
#
# Name Version Build Channel
_ipyw_jlab_nb_ext_conf 0.1.0 py36h2fc01ae_0
alabaster 0.7.10 py36h174008c_0
amqp 2.2.2 <pip>
anaconda 5.1.0 py36_2
anaconda-client 1.6.9 py36_0
To grab the entries installed by pip
(including possibly pip
itself):
user@pc:~ $ conda list | grep \<pip
amqp 2.2.2 <pip>
astroid 1.6.2 <pip>
billiard 3.5.0.3 <pip>
blinker 1.4 <pip>
ez-setup 0.9 <pip>
feedgenerator 1.9 <pip>
Of course you probably want to just select the first column, which you can do with (excluding pip
if needed):
user@pc:~ $ conda list | awk '$3 ~ /pip/ {if ($1 != "pip") print $1}'
amqp
astroid
billiard
blinker
ez-setup
feedgenerator
Finally you can grab these values and pip uninstall all of them using the following:
user@pc:~ $ conda list | awk '$3 ~ /pip/ {if ($1 != "pip") print $1}' | xargs pip uninstall -y
Note the use of the -y
flag for the pip uninstall
to avoid having to give confirmation to delete.

- 1,363
- 1
- 17
- 26
-
This is the same as [2nd highest voted answer](https://stackoverflow.com/a/16759140/2745495). – Gino Mempin Dec 31 '19 at 01:28
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.

- 776,304
- 153
- 1,341
- 1,358
At least for Ubuntu (maybe also others) works this (inspired by a previous post in this thread):
printf "Installed with pip:";
pip list 2>/dev/null | gawk '{print $1;}' | while read; do pip show "${REPLY}" 2>/dev/null | grep 'Location: /usr/local/lib/python2.7/dist-packages' >/dev/null; if (( $? == 0 )); then printf " ${REPLY}"; fi; done; echo

- 759
- 9
- 12
pip list:
pip list
This will get the list of installed packages along with their version in angular braces
pip List has multiple options like
List outdated packages
python -m pip list --outdated
This will List all outdated packages installed in python.
List all updated packages
python -m pip list -u
This will list all package that are upto date.
List outdated packages with no dependencies
python -m pip list --outdated --not-required
This will List all outdated packages that are not dependencies of other packages.
List all the packages in json format
python -m pip list --format=json
For More details Refer : https://www.datasciencemadesimple.com/list-packages-modules-installed-python/
pip freeze:
We can Also use
pip freeze
This will get the list of installed packages along with their version as shown below

- 101
- 1
- 6