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).
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
Here is the one-liner for fedora or other rpm distros (based on @barraponto tips):
Append this to the previous command to get cleaner output:
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#259747I am an ArchLinux user and as I experimented with pip I met this same problem. Here's how I solved it in Arch.
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
becausepacman -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 (justsudo pip install
something), how to query ownership of a file (Debian/Ubuntu method isdpkg -S
) and what is the "no package owns that path" return (Debian/Ubuntu isno path found matching pattern
). Debian/Ubuntu users, beware:dpkg -S
will fail if you give it a symbolic link. Just resolve it first by usingrealpath
. Like this:Fedora users can try (thanks @eddygeek):
For those who don't have pip installed, I found this quick script on github (works with Python 2.7.13):
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:
To accomplish this, you can import
pkg_resources
. Here's an example:I'm on
v3.6.5
If you use the Anaconda python distribution, you can use the
conda list
command to see what was installed by what method:To grab the entries installed by
pip
(including possiblypip
itself):Of course you probably want to just select the first column, which you can do with (excluding
pip
if needed):Finally you can grab these values and pip uninstall all of them using the following:
Note the use of the
-y
flag for thepip uninstall
to avoid having to give confirmation to delete.Get all file/folder names in
site-packages/
(anddist-packages/
if it exists), and use your package manager to strip the ones that were installed via package.