707

Python's easy_install makes installing new packages extremely convenient. However, as far as I can tell, it doesn't implement the other common features of a dependency manager - listing and removing installed packages.

What is the best way of finding out what's installed, and what is the preferred way of removing installed packages? Are there any files that need to be updated if I remove packages manually (e.g. by rm /usr/local/lib/python2.6/dist-packages/my_installed_pkg.egg or similar)?

ire_and_curses
  • 64,177
  • 22
  • 110
  • 139
  • 67
    this post is nearly 2 years old at the time I'm writing this comment. pip is now effectively a replacement for easy_install and can properly and cleanly remove packages (eggs included) installed by the latter. Please make sure to upvote the answer suggesting it further down the thread. – Michael Ekoka Mar 15 '11 at 01:50
  • 54
    The oxymoron that something called ***"easy_install"*** - doesn't **a:** have a counterpart `easy_uninstall`, nor **b:** bother to mention how one may do so in the `--help` - _boggles my mind / _infuriates my soul / saddens my heart_. – Alex Gray Sep 24 '13 at 04:17
  • 13
    @mike what if I'm trying to uninstall pip? (: – mccc Dec 16 '14 at 16:04

13 Answers13

620

pip, an alternative to setuptools/easy_install, provides an "uninstall" command.

Install pip according to the installation instructions:

$ wget https://bootstrap.pypa.io/get-pip.py
$ python get-pip.py

Then you can use pip uninstall to remove packages installed with easy_install

lunaryorn
  • 31,344
  • 5
  • 68
  • 85
  • Hey it actually does! Thanks! I was annoyed at one point that it didn't. For some reason my system was stuck at version 0.3.1 of `pip`; I had to feed `easy_install` the URL to the tarball for version 0.8.1 in order to update to a version that has the `uninstall` command. – intuited Sep 25 '10 at 04:03
  • 25
    if you're having issues uninstalling modules with pip, make sure your pip installation itself is up to date: pip install -U pip # that's an uppercase U – Michael Ekoka Mar 15 '11 at 01:51
  • 4
    pip worked for me to uninstall an easy_install installed package. I had to run 'pip uninstall ' multiple times to remove all versions of the package, though. So keep that in mind. It even removed a 'develop' installed package, which was kind of a mess as a result. – DragonFax Jul 29 '13 at 04:54
  • 2
    But How would you delete non-active package – CrazyGeek Mar 13 '14 at 19:17
  • 8
    I used easy_install to install pip to uninstall easy_install installs. –  Feb 13 '15 at 07:09
  • This doesn't work the way you expect if the package you installed, installed other packages alongside it. That is, you have to uninstall its dependencies "manually" through a sequence of "pip uninstall someDependency" statements. – Lightyear Buzz Jun 29 '15 at 02:22
  • 2
    The answer says "install pip", but **actually pip seems to come built in with modern Python**. – Edward Jan 28 '16 at 19:31
  • any idea how to uninstall pip package containing a key word? – JinSnow Nov 24 '16 at 08:21
  • I had packages installed with setuptools, and pip could not find them. The answer by @joeforker worked for me. – dfrankow Feb 20 '17 at 22:53
  • ironic - to uninstall, first you must install something else! – Michael Apr 29 '19 at 18:45
  • Note: You can run this script with either `python` for python2.x-pip or `python3` for python3.x-pip. If you run into problems try `sudo -H python3 get-pip.py` where the `3` is optional. – jaaq May 28 '19 at 14:59
191

To uninstall an .egg you need to rm -rf the egg (it might be a directory) and remove the matching line from site-packages/easy-install.pth

joeforker
  • 36,731
  • 34
  • 138
  • 231
  • 18
    The newer `pip` package manager includes an uninstall feature. – joeforker Nov 17 '10 at 16:24
  • I find pip better then uninstall, because pip install from sources. If you have like me a brand new Win7 64bit, it will save your days :) – daitangio Jun 09 '11 at 07:11
  • 6
    Some of use are stuck with an old version of pip that doesn't have the uninstall option, so this answer still has worth. – Mark Pitchless Sep 03 '12 at 16:43
  • 5
    Probably worth mentioning that this method may leave stray `data_files` and `scripts` (and possibly other file categories) on the system. The egg's `EGG-INFO/SOURCES.txt` contains a list of all `package` files and `sources`, but not `data_files`, which can be installed into any arbitrary directory on your system... – Alex Leach Jul 01 '13 at 11:11
  • pip doesn't always remove all of what easy_install installs. [Here's a little experience](https://gist.githubusercontent.com/ychaouche/81121a0d3e59400f3e61/raw/aa96eedcc3cb13d8dc56dcf4f72ec98b236e9109/gistfile1.txt) that just happened to me where pip was unable to uninstall one of my modules. I had to remove the matching line from site-packages/easy-install.pth to completely uninstall it. – ychaouche Mar 03 '15 at 11:09
  • it also helps when you have to manually move eggs from user to global or another user – Edi Bice Apr 21 '16 at 18:25
  • Still necessary to have a chance cleaning up from easy_install. The pip3 program says, nothing to remove since cffi not installed. Yet, the tests from cffi finds the version mismatch from the easy_install grabbing an older version 1.10 versus the 1.11.5. – CPlusPlus OOA and D Apr 23 '18 at 21:32
162

First you have to run this command:

$ easy_install -m [PACKAGE]

It removes all dependencies of the package.

Then remove egg file of that package:

$ sudo rm -rf /usr/local/lib/python2.X/site-packages/[PACKAGE].egg
Gray
  • 108,756
  • 21
  • 270
  • 333
PythonDev
  • 4,149
  • 6
  • 28
  • 37
  • 1
    more doc here: http://peak.telecommunity.com/DevCenter/EasyInstall#uninstalling-packages – GiDo Feb 17 '13 at 01:34
  • `-m` is not the proper easy_install command to remove anything as far as I can tell, but this answer gives the crucial location of the easy_install packages that other answers do not. an `rm -rf /usr/local/lib/python*` prior to installing pip is the way to go it seems to me – fuzzyTew Nov 02 '16 at 02:35
55

All the info is in the other answers, but none summarizes both your requests or seem to make things needlessly complex:

  • For your removal needs use:

    pip uninstall <package>
    

    (install using easy_install pip)

  • For your 'list installed packages' needs either use:

    pip freeze
    

    Or:

    yolk -l
    

    which can output more package details.

    (Install via easy_install yolk or pip install yolk)

the Tin Man
  • 150,910
  • 39
  • 198
  • 279
Rabarberski
  • 21,632
  • 19
  • 69
  • 85
  • After running `yolk -l`, I see that I have duplicate packages such as "scipy -0.11.0 -non-active development" and "scipy -0.14.0... -active development". How can I uninstall these non-active development packages? – bobbyjoe93 Mar 31 '14 at 05:04
  • 2
    This is good except I want to uninstall pip which was installed by easy_install. This is because it ended up installing it for the wrong Python version. – Nagev Sep 18 '17 at 13:47
28

There are several sources on the net suggesting a hack by reinstalling the package with the -m option and then just removing the .egg file in lib/ and the binaries in bin/. Also, discussion about this setuptools issue can be found on the python bug tracker as setuptools issue 21.

Edit: Added the link to the python bugtracker.

c089
  • 4,685
  • 2
  • 22
  • 36
  • 2
    Thanks for this info. For other's reference, here's the link to the issue that you mentioned: http://bugs.python.org/setuptools/issue21 – ire_and_curses Aug 05 '09 at 09:05
25

If the problem is a serious-enough annoyance to you, you might consider virtualenv. It allows you to create an environment that encapsulates python libraries. You install packages there rather than in the global site-packages directory. Any scripts you run in that environment have access to those packages (and optionally, your global ones as well). I use this a lot when evaluating packages that I am not sure I want/need to install globally. If you decide you don't need the package, it's easy enough to just blow that virtual environment away. It's pretty easy to use. Make a new env:

$>virtualenv /path/to/your/new/ENV

virtual_envt installs setuptools for you in the new environment, so you can do:

$>ENV/bin/easy_install

You can even create your own boostrap scripts that setup your new environment. So, with one command, you can create a new virtual env with, say, python 2.6, psycopg2 and django installed by default (you can can install an env-specific version of python if you want).

mazelife
  • 1,989
  • 16
  • 12
19

Official(?) instructions: http://peak.telecommunity.com/DevCenter/EasyInstall#uninstalling-packages

If you have replaced a package with another version, then you can just delete the package(s) you don't need by deleting the PackageName-versioninfo.egg file or directory (found in the installation directory).

If you want to delete the currently installed version of a package (or all versions of a package), you should first run:

easy_install -mxN PackageName

This will ensure that Python doesn't continue to search for a package you're planning to remove. After you've done this, you can safely delete the .egg files or directories, along with any scripts you wish to remove.

gnat
  • 6,199
  • 101
  • 49
  • 71
Mark Rajcok
  • 348,511
  • 112
  • 482
  • 482
  • Some things never change it seems! PIP refused to install a TRAC hack plugin (trac admin), only easy_install works. But I accidently installed an old version. And easy_install was not able to fix that from the https url for the project. So I used PIP to remove it, but after re-installing TRAC does not see the plugin. So I use the info here to isolate the pkg and manually delete it, then re-install. whew. (python 2.7) – Richard Cooke Feb 04 '18 at 02:22
16

try

$ easy_install -m [PACKAGE]

then

$ rm -rf .../python2.X/site-packages/[PACKAGE].egg
Jim Geovedi
  • 161
  • 1
  • 2
  • 1
    To remove a package: `$ easy_install -mxN PACKAGE` then `$ rm -rf .../lib/python2.X/site-packages/PACKAGE.egg` (See http://peak.telecommunity.com/DevCenter/EasyInstall#uninstalling-packages) – Vinicius José Latorre Jul 31 '14 at 04:19
7

To list installed Python packages, you can use yolk -l. You'll need to use easy_install yolk first though.

the Tin Man
  • 150,910
  • 39
  • 198
  • 279
Enis Afgan
  • 180
  • 1
  • 5
6

Came across this question, while trying to uninstall the many random Python packages installed over time.

Using information from this thread, this is what I came up with:

cat package_list | xargs -n1 sudo pip uninstall -y

The package_list is cleaned up (awk) from a pip freeze in a virtualenv.

To remove almost all Python packages:

yolk -l | cut -f 1 -d " " | grep -v "setuptools|pip|ETC.." | xargs -n1 pip uninstall -y
the Tin Man
  • 150,910
  • 39
  • 198
  • 279
m0hit
  • 61
  • 1
  • 2
3

For me only deleting this file : easy-install.pth worked, rest pip install django==1.3.7

Snehal Parmar
  • 4,437
  • 3
  • 32
  • 42
3

I ran into the same problem on my MacOS X Leopard 10.6.blah.

Solution is to make sure you're calling the MacPorts Python:

sudo port install python26
sudo port install python_select
sudo python_select python26
sudo port install py26-mysql

Hope this helps.

the Tin Man
  • 150,910
  • 39
  • 198
  • 279
Cmag
  • 12,570
  • 23
  • 75
  • 129
  • 1
    However, I've completely switched away from MacPorts to either Brew, native python 2.7 from mac. MySQLdb installed via setup_tools – Cmag Jan 01 '12 at 15:18
0

This worked for me. It's similar to previous answers but the path to the packages is different.

  1. sudo easy_install -m
  2. sudo rm -rf /Library/Python/2.7/site-packages/.egg

Plaform: MacOS High Sierra version 10.13.3

Red Rooster
  • 151
  • 1
  • 4
  • 2
    first command produces this error for me: `error: No urls, filenames, or requirements specified (see --help)` – Michael Apr 29 '19 at 18:46