How to uninstall editable packages with pip (installed with -e)
Asked Answered
P

7

166

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?

Podvin answered 27/6, 2013 at 14:58 Comment(8)
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_pointsPasteur
for people using conda, to uninstall in dev mode in conda do: conda develop -u .Pushed
Did you figure out why pip uninstall yourpackage did not work? Like what your errors mean? Seems odd output from the command...Pushed
Did you try pip uninstall -e . or python setup.py develop -u?Pushed
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)?Pushed
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.Pushed
@CharlieParker yes path/to/pythonX.Y -m pip uninstall library should work. If it doesn't, then probably something went wrong at some point.Longsome
@Longsome 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.Pushed
A
120

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).
Antiworld answered 16/9, 2013 at 0:25 Comment(15)
Kind of surprise there is no corresponding uninstall way for that.Bonaventure
@Drake yes, pretty annoying actuallyAntiworld
With the current pip version the uninstall is working alright also for packages installed with -e option.Bags
@Bags For the sake of making it clear to everybody, which version is the you refer to? ThanksAntiworld
@Antiworld Oh, sorry for incompleteness, it's pip version 1.5.4, which I'm currently using like thisBags
@Bags that's strange, because i'm using pip 1.5.6 and i had to delete it from both places as here https://mcmap.net/q/24264/-how-to-uninstall-editable-packages-with-pip-installed-with-e is mentionedBinion
With pip 8.1.1 and this is still an issue that requires manual modifications.Baluchistan
for me using 8.1.2, pip uninstall package_name works, but pip uninstall . doesn't workConcerned
There is an open issue against pip here for the ability to remove editable-installed packages.Diacaustic
See related https://mcmap.net/q/24268/-removing-python-module-installed-in-develop-mode . It turns out that pip was just using setuptools develop mode. python setup.py develop --uninstallPoulter
Still an issue with pip 19.2.2Kirkuk
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?Pushed
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)?Pushed
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 workPushed
Since your answer is accepted right now, can you edit the answer to add the new method (pip uninstall package_name)?Hurtado
W
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$ 
Wheeler answered 13/6, 2019 at 8:59 Comment(6)
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?Pushed
What is the "new version of setup_tools" that has this answer work? Can you confirm this please?Pushed
Does your answer guarantee that one doesn't have to remove thins manually?Pushed
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?Wheeler
@CharlieParker I am not sure which version this was introduced in. I've never had to manually remove these files.Wheeler
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 workPushed
C
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

Currey answered 16/6, 2017 at 4:26 Comment(10)
Can you specify where you are running that second command from please?Lactic
@Lactic . is the current directory, you use the full absolute path of the package.Currey
Incomplete. What about all the Python packages? (site-packages dir)Prepositive
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.Nemhauser
@MarkAmery Thanks, pip uninstall package_name work now.Currey
How is your answer different from python setup.py develop -u?Pushed
@Charlie path/to/pythonX.Y setup.py develop --uninstall should also uninstall, but I recommend using the pip way instead.Longsome
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 workPushed
This is not correct, some files are added to the virtual environment and not deleted.Scarfskin
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.Scarfskin
G
20

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

pip uninstall yourpackage

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

Gettogether answered 22/9, 2016 at 2:12 Comment(8)
OP has tried this and says so in his question. This does not necessarily work with packages installed as 'editable'Florrie
@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.Gettogether
@Gettogether wait are you saying that works even for editable mode?Pushed
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.Pushed
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.Hamachi
Worked for me with git version 20.30.0. My package was installed with pip install -e .Elberfeld
pip 20.1.1 work for me thisTilton
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 '<package>'. No files were found to uninstall.. What solved it for me was the simple, safe-looking, copy-and-paste, one-liner from @AhmedShariff.Postern
P
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
...
Podvin answered 27/6, 2013 at 15:15 Comment(2)
What does it mean that your installation was corrupt?Pushed
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.Postern
Z
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

Zoba answered 19/11, 2017 at 16:7 Comment(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 workPushed
W
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!

Wolfson answered 13/9, 2022 at 13:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.