164

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?

Michael_Scharf
  • 33,154
  • 22
  • 74
  • 95
  • 10
    pip uninstall 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 – picmate 涅 Oct 22 '19 at 20:06
  • 1
    for people using conda, to uninstall in dev mode in conda do: `conda develop -u .` – Charlie Parker Apr 28 '20 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... – Charlie Parker May 02 '20 at 16:07
  • 1
    Did you try `pip uninstall -e .` or `python setup.py develop -u`? – Charlie Parker May 02 '20 at 16:15
  • I am sort of confused with so many answers going on. What exactly do we need to do? In what situation do we need to remove things manually and in which ones do we need not? I know the different options are `python setup.py develop -u`, `pip uninstall library`, `pip uninstall -e .` and `pip uninstall -r requirements.txt`. So which one do we do in what situation and which one needs to remove extra stuff by hand (& for what versions of pip and python do we not need to worry by removing things by hand)? – Charlie Parker May 02 '20 at 16:19
  • 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. – Charlie Parker May 02 '20 at 16:34
  • @CharlieParker yes `path/to/pythonX.Y -m pip uninstall library` should work. If it doesn't, then probably something went wrong at some point. – sinoroc May 02 '20 at 18:31
  • @sinoroc my point is that `pip uninstall library` should work and as the OP admitted in his own answer to his won question, the most likely reason things were not working with him was because his computer & installations were in a weird state. – Charlie Parker May 02 '20 at 20:39

7 Answers7

118

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).
Zitrax
  • 19,036
  • 20
  • 88
  • 110
glarrain
  • 8,031
  • 7
  • 31
  • 44
  • 65
    Kind of surprise there is no corresponding uninstall way for that. – Drake Guan Oct 30 '13 at 13:15
  • 4
    @Drake yes, pretty annoying actually – glarrain Oct 30 '13 at 14:24
  • 6
    With the current pip version the uninstall is working alright also for packages installed with `-e` option. – famousgarkin Feb 21 '14 at 16:44
  • @famousgarkin For the sake of making it clear to everybody, which version is the you refer to? Thanks – glarrain Feb 26 '14 at 20:39
  • 1
    @glarrain Oh, sorry for incompleteness, it's pip version 1.5.4, which I'm currently using like this – famousgarkin Mar 04 '14 at 12:30
  • 2
    @famousgarkin that's strange, because i'm using pip 1.5.6 and i had to delete it from both places as here http://stackoverflow.com/a/18818891/740067 is mentioned – xliiv Aug 23 '14 at 21:26
  • 1
    With pip 8.1.1 and this is still an issue that requires manual modifications. – JAR.JAR.beans Apr 06 '16 at 10:14
  • 14
    for me using 8.1.2, `pip uninstall package_name` works, but `pip uninstall .` doesn't work – confused00 Oct 02 '16 at 12:43
  • 6
    There is an open issue against pip [here](https://github.com/pypa/pip/issues/4438) for the ability to remove editable-installed packages. – Chris Hunt May 13 '17 at 18:00
  • 1
    See related https://stackoverflow.com/a/3623868/642372 . It turns out that pip was just using setuptools develop mode. `python setup.py develop --uninstall` – Walker Hale IV Jun 07 '19 at 21:53
  • Still an issue with pip 19.2.2 – Colin 't Hart Aug 16 '19 at 08:58
  • I guess these instructions don't work if you are using pip AND conda together? I can't find anything such as `site-packages` in my `~/anaconda3/envs/myenv` in my environment...where would it be if I installed it with `pip install -e` but I am using `conda` too? – Charlie Parker Apr 27 '20 at 20:42
  • I am sort of confused with so many answers going on. What exactly do we need to do? In what situation do we need to remove things manually and in which ones do we need not? I know the different options are `python setup.py develop -u`, `pip uninstall library`, `pip uninstall -e .` and `pip uninstall -r requirements.txt`. So which one do we do in what situation and which one needs to remove extra stuff by hand (& for what versions of pip and python do we not need to worry by removing things by hand)? – Charlie Parker May 02 '20 at 16:18
  • 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 – Charlie Parker May 09 '20 at 20:49
  • Since your answer is accepted right now, can you edit the answer to add the new method (pip uninstall package_name)? – user202729 Nov 11 '20 at 14:02
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$ 
Martin Dorey
  • 2,944
  • 2
  • 24
  • 16
Ahmed Shariff
  • 793
  • 6
  • 12
  • 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? – Charlie Parker Apr 27 '20 at 20:39
  • What is the "new version of setup_tools" that has this answer work? Can you confirm this please? – Charlie Parker May 02 '20 at 16:09
  • Does your answer guarantee that one doesn't have to remove thins manually? – Charlie Parker May 02 '20 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](https://setuptools.readthedocs.io/en/latest/setuptools.html#development-mode). After running this does it still load the content from the development directory? – Ahmed Shariff May 04 '20 at 04:01
  • @CharlieParker I am not sure which version this was introduced in. I've never had to manually remove these files. – Ahmed Shariff May 04 '20 at 04:02
  • 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 – Charlie Parker May 09 '20 at 20:49
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

Legolas Bloom
  • 1,725
  • 1
  • 19
  • 17
  • 4
    Can you specify where you are running that second command from please? – ethanabrooks Nov 21 '18 at 13:50
  • 1
    @ethanabrooks `.` is the current directory, you use the full absolute path of the package. – Legolas Bloom Nov 28 '18 at 01:24
  • 1
    Incomplete. What about all the Python packages? (`site-packages` dir) – Jorge Orpinel Pérez Jun 01 '19 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 Jan 11 '20 at 14:23
  • @MarkAmery Thanks, `pip uninstall package_name` work now. – Legolas Bloom Jan 16 '20 at 05:59
  • How is your answer different from `python setup.py develop -u`? – Charlie Parker May 02 '20 at 16:12
  • 1
    @Charlie `path/to/pythonX.Y setup.py develop --uninstall` should also uninstall, but I recommend using the _pip_ way instead. – sinoroc May 02 '20 at 18:34
  • 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 – Charlie Parker May 09 '20 at 20:49
  • This is not correct, some files are added to the virtual environment and not deleted. – NeoZoom.lua Sep 10 '21 at 00:50
  • E.g. I'm using Minconda installed with Homebrew. On `/usr/local/Caskroom/minconda/base/envs/ENV_NAME/lib/python3.9/site-packages` there are two files added: `easy-install.pth`, `src.egg-link`. – NeoZoom.lua Sep 10 '21 at 00:56
15

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

pip uninstall yourpackage

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

ead
  • 32,758
  • 6
  • 90
  • 153
Apteryx
  • 5,822
  • 3
  • 16
  • 18
  • 13
    OP has tried this and says so in his question. This does not necessarily work with packages installed as 'editable' – dusktreader Apr 05 '17 at 00:05
  • 3
    @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 May 31 '17 at 18:27
  • 1
    @Apteryx wait are you saying that works even for editable mode? – Charlie Parker May 02 '20 at 16:05
  • 2
    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. – Charlie Parker May 02 '20 at 20:37
  • 1
    Tried this `pip uninstall an-editable-package-0.1.0` and got `WARNING: Skipping an-editable-package-0.1.0 as it is not installed.`, but it was most definitely installed with `pip install -e an-editable-package-0.1.0`. – Walf Nov 27 '20 at 01:50
  • 1
    Worked for me with git version 20.30.0. My package was installed with `pip install -e .` – Jasha Feb 17 '21 at 21:05
  • pip 20.1.1 work for me this – Tiana987642 Oct 06 '21 at 07:31
  • It claimed to have worked for me with pip 20.3.4, but left bits of the package available to be imported and, on a retry, it just said `Can't uninstall ''. No files were found to uninstall.`. What solved it for me was the simple, safe-looking, copy-and-paste, one-liner from @AhmedShariff. – Martin Dorey Jun 02 '22 at 19:13
6

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
...
Michael_Scharf
  • 33,154
  • 22
  • 74
  • 95
  • 2
    What does it mean that your installation was corrupt? – Charlie Parker May 02 '20 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. – Martin Dorey Jun 02 '22 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

Community
  • 1
  • 1
matt wilkie
  • 17,268
  • 24
  • 80
  • 115
  • 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 – Charlie Parker May 09 '20 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!