170

I have installed some packages with -e

> pip install -e git+https://github.com/eventray/horus.git@2ce62c802ef5237be1c6b1a91dbf115ec284a619#egg=horus-dev

I with pip freeze I see

> pip freeze
...
-e git+https://github.com/eventray/horus.git@2ce62c802ef5237be1c6b1a91dbf115ec284a619#egg=horus-dev
...

when I try to uninstall the packages I get errors:

> pip uninstall horus-dev
Cannot uninstall requirement horus-dev, not installed

> pip uninstall horus
Cannot uninstall requirement horus, not installed

How do I uninstall such a package?

8
  • 11
    pip uninstall <package> uninstalls packages installed in the editable mode in recent versions of pip (mine is 19.1.1). Make sure to use the package name in setup.py, not the alias you specify to call that package in entry_points Commented Oct 22, 2019 at 20:06
  • 1
    for people using conda, to uninstall in dev mode in conda do: conda develop -u . Commented Apr 28, 2020 at 15:58
  • Did you figure out why pip uninstall yourpackage did not work? Like what your errors mean? Seems odd output from the command... Commented May 2, 2020 at 16:07
  • 1
    Did you try pip uninstall -e . or python setup.py develop -u? Commented May 2, 2020 at 16:15
  • 4
    For me pip uninstall library worked just fine. If you go to the answer the OP provided it seems it's something weird with his library that was corrupted. Hopefully this saves people time next time they come here. Though, there are many different options that might work. Commented May 2, 2020 at 16:34

7 Answers 7

121

At {virtualenv}/lib/python2.7/site-packages/ (if not using virtualenv then {system_dir}/lib/python2.7/dist-packages/)

  • remove the egg file (e.g. distribute-0.6.34-py2.7.egg) if there is any
  • from file easy-install.pth, remove the corresponding line (it should be a path to the source directory or of an egg file).
15
  • 70
    Kind of surprise there is no corresponding uninstall way for that.
    – Drake Guan
    Commented Oct 30, 2013 at 13:15
  • 4
    @Drake yes, pretty annoying actually
    – glarrain
    Commented Oct 30, 2013 at 14:24
  • 6
    With the current pip version the uninstall is working alright also for packages installed with -e option. Commented Feb 21, 2014 at 16:44
  • 14
    for me using 8.1.2, pip uninstall package_name works, but pip uninstall . doesn't work
    – confused00
    Commented Oct 2, 2016 at 12:43
  • 6
    There is an open issue against pip here for the ability to remove editable-installed packages.
    – Chris Hunt
    Commented May 13, 2017 at 18:00
47

An easier way to do the same with the new version of setup_tools is to run the following:

python setup.py develop -u

Which basically does the same as what @glarrain describes in his answer.

Here's a demonstration, showing that eg you don't want to substitute a package name into that command:

.../pytest-migration$ python setup.py develop -u
running develop
Removing /home/me/virtualEnvs/automation/lib/python2.7/site-packages/pytest-migration.egg-link (link to .)
Removing pytest-migration 1.0.155 from easy-install.pth file
.../pytest-migration$ 
6
  • 2
    is there supposed to be any output to that command? I get it says running develop but I still the .egg-info file...is it suppose to remove it? Commented Apr 27, 2020 at 20:39
  • What is the "new version of setup_tools" that has this answer work? Can you confirm this please? Commented May 2, 2020 at 16:09
  • Does your answer guarantee that one doesn't have to remove thins manually? Commented May 2, 2020 at 16:12
  • It doesn't produce any outputs. According to my understanding it should remove it: "--uninstall, -u Un-deploy the current project. You may use the --install-dir or -d option to designate the staging area. The created .egg-link file will be removed, if present and it is still pointing to the project directory." from setuptools docs. After running this does it still load the content from the development directory? Commented May 4, 2020 at 4:01
  • @CharlieParker I am not sure which version this was introduced in. I've never had to manually remove these files. Commented May 4, 2020 at 4:02
28

Install a dev package use cmd:

pip install --editable .

Uninstall:

rm -r $(find . -name '*.egg-info')

Now you can use:

pip uninstall package_name 

or python setup.py develop --uninstall or python setup.py develop -u

10
  • 4
    Can you specify where you are running that second command from please? Commented Nov 21, 2018 at 13:50
  • 1
    @ethanabrooks . is the current directory, you use the full absolute path of the package. Commented Nov 28, 2018 at 1:24
  • 1
    Incomplete. What about all the Python packages? (site-packages dir) Commented Jun 1, 2019 at 18:14
  • 1
    This doesn't fully undo the install. It deletes stuff from folder that the package was installed from, but doesn't delete the symlink in your dist-packages directory (where Python looks for the installed package). Cleaner to use python setup.py develop -u.
    – Mark Amery
    Commented Jan 11, 2020 at 14:23
  • 1
    @Charlie path/to/pythonX.Y setup.py develop --uninstall should also uninstall, but I recommend using the pip way instead.
    – sinoroc
    Commented May 2, 2020 at 18:34
20
+50

Simply uninstall the package you installed in 'editable' mode:

pip uninstall yourpackage

it works for recent pip-versions (at least >=19.1.1).

8
  • 14
    OP has tried this and says so in his question. This does not necessarily work with packages installed as 'editable' Commented Apr 5, 2017 at 0:05
  • 4
    @dusktreader: I'm not sure what's going on with OP's pip uninstall command (maybe an outdated version of pip?), but I've verified that under normal circumstances it does exactly what was suggested to do manually in the accepted answer by @glarrain. If it's not working out for you, please detail what you're doing here so that we may dig the issue further.
    – Apteryx
    Commented May 31, 2017 at 18:27
  • 1
    @Apteryx wait are you saying that works even for editable mode? Commented May 2, 2020 at 16:05
  • 3
    This answer worked for me. I think it didn't work for the OP because if you check his answer he had some weird corrupted installation (or his computer was in a weird state). pip uninstall pkg works afaik. Commented May 2, 2020 at 20:37
  • 2
    Worked for me with git version 20.30.0. My package was installed with pip install -e .
    – Jasha
    Commented Feb 17, 2021 at 21:05
7

It turns out that my installation was somehow corrupt.

I could find the entry in:

/usr/local/lib/python2.7/site-packages/easy-install.pth

To solve the problem I removed the line in the .pth file by hand!

import sys; sys.__plen = len(sys.path)
...
/absolute-path-to/horus  # <- I removed this line
...
2
  • 2
    What does it mean that your installation was corrupt? Commented May 2, 2020 at 16:14
  • Yeah, I bet it wasn't corrupt, it's just really surprising, as comments there say, that, per the answer from glarrain, you're expected to make such an edit... except that, per the answer from Ahmed Shariff, there's a clean way to request that it be done for you. Commented Jun 2, 2022 at 19:53
5

This is a bug on debian/ubuntu linux using OS-installed pip (v8.1.1 for me), which is what you'll invoke with sudo pip even if you've upgraded pip (e.g. get-pip.py). See https://github.com/pypa/pip/issues/4438

For a discussion on how to clean up see https://askubuntu.com/questions/173323/how-do-i-detect-and-remove-python-packages-installed-via-pip, though the solutions there are of the "remove everything" variety.

...pip packages [go] to /usr/local/lib/python2.7/dist-packages, and apt packages to /usr/lib/python2.7/dist-packages

...a few packages were installed in ~/.local/lib too.

For my system all I needed to remove was /usr/local/lib/python2.7/dist-packages/{package_name}.egg-link

1
  • For me pip uninstall library worked just fine. If you go to the answer the OP provided it seems it's something weird with his library that was corrupted. Hopefully this saves people time next time they come here. Though, there are many different options that might work Commented May 9, 2020 at 20:50
0

I think I have something to add to all the answers here:

Using pip list you'll see all your installed packages, and there is a little trickery: a single pip install can create several entries in this list. In particular when you do an editable install, you'll have your <package_name> listed besides the location of the source on your disc.

This <package_name> is only used for pip and is never called in python as far as I understand, it is configured in your pyproject.toml, setup.cfg or setup.py.

Thus, to properly uninstall your package using pip, you should use this name and not the named of individual modules included in your package.

Hope it helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.