Michael_Scharf
Michael_Scharf

Reputation: 34508

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

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?

Upvotes: 172

Views: 67584

Answers (8)

zsh
zsh

Reputation: 1

Edit: This is a straightforward solution. This solution worked when the .pth file was empty and there were no .egg files but egg-link files.
pip only fails at deleting the .egg-link file, rest is handled.

For installs done in conda environment,

pip uninstall package_name

then delete the .egg-link file in
path_to/miniconda(anaconda)/envs/<env_name>/Lib/site-packages/<package_name>.egg-link

Upvotes: 0

Assombrance Andreson
Assombrance Andreson

Reputation: 431

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!

Upvotes: 0

Ahmed Shariff
Ahmed Shariff

Reputation: 793

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$ 

Upvotes: 47

Apteryx
Apteryx

Reputation: 6352

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

pip uninstall yourpackage

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

Upvotes: 22

Legolas Bloom
Legolas Bloom

Reputation: 1805

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

Upvotes: 28

matt wilkie
matt wilkie

Reputation: 18084

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

Upvotes: 6

glarrain
glarrain

Reputation: 8449

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).

Upvotes: 121

Michael_Scharf
Michael_Scharf

Reputation: 34508

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
...

Upvotes: 7

Related Questions