pip: pip uninstall not working with editable dependencies

  • Pip version: 10.0.0b2 as well as 10.0.0b2+ (8e074408d69f4b1e064dbc8908f1ec7dcf034be5)
  • Python version: 2.7.12
  • Operating system: Ubuntu 16.04

Description:

After installing an editable dependency from vcs, it cannot be uninstalled. With pip 9 it did uninstall correctly, removing the .egg-link file.

What I’ve run:

$ virtualenv --version
15.0.1
$ virtualenv venv
$ venv/bin/pip --version  
10.0.0b2  # wondering why I'm getting a beta version of pip without asking but that's not the point here
$ venv/bin/pip install -e git+https://github.com/pallets/click.git#egg=click
Obtaining click from git+https://github.com/pallets/click.git#egg=click
  Updating ./venv/src/click clone
Installing collected packages: click
  Running setup.py develop for click
Successfully installed click
$ venv/bin/pip uninstall click
Can't uninstall 'click'. No files were found to uninstall.
$ venv/bin/pip list
Package       Version  Location                          
------------- -------- ----------------------------------
click         7.0.dev0 /home/sbi-local/tmp/venv/src/click
pip           10.0.0b2 
pkg-resources 0.0.0    
setuptools    39.0.1   
wheel         0.31.0   

I expected click to be uninstalled at this point.

If I downgrade to pip 9.0.3, it works:

$ venv/bin/pip install pip==9.0.3
Collecting pip==9.0.3
  Using cached pip-9.0.3-py2.py3-none-any.whl
Installing collected packages: pip
  Found existing installation: pip 10.0.0b2
    Uninstalling pip-10.0.0b2:
      Successfully uninstalled pip-10.0.0b2
Successfully installed pip-9.0.3
$ venv/bin/pip uninstall click
Uninstalling click-7.0.dev0:
  /home/sbi-local/tmp/venv/lib/python2.7/site-packages/click.egg-link
Proceed (y/n)? y
  Successfully uninstalled click-7.0.dev0
$ venv/bin/pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
pip (9.0.3)
pkg-resources (0.0.0)
setuptools (39.0.1)
wheel (0.31.0)

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 46 (35 by maintainers)

Most upvoted comments

Well, consider myself nerdsniped 😆

I attempted to bisect this, hope this is helpful 😃

#!/usr/bin/env bash
set -euxo pipefail

export PIP_DISABLE_PIP_VERSION_CHECK=1 VIRTUALENV_NO_DOWNLOAD=1

finish() {
    git checkout -- .
    git clean -fxfd
}
trap finish ERR EXIT

# hotfix for `AttributeError: 'module' object has no attribute 'get_python_lib'
# cherry-picked from 310bcfc78fea8f1f2bc4f680b376e18bf5aeed07
if \
    grep -q '^import sysconfig$' pip/locations.py && \
    grep -q 'site_packages = sysconfig.get_python_lib()$' pip/locations.py; then
    sed -i 's/sysconfig.get_python_lib()/sysconfig.get_path("purelib")/g' pip/locations.py
fi

mkdir tdir
(
    cd tdir

    echo 'from setuptools import setup; setup(name="pkg")' > setup.py
    virtualenv venv -ppython2 > /dev/null
    venv/bin/pip install ../ > /dev/null || exit 125
    venv/bin/pip install -e . > /dev/null || exit 125
    ! (venv/bin/pip uninstall -y pkg | grep 'Not uninstalling pkg')
)

I had to apply the patch listed in 310bcfc78fea8f1f2bc4f680b376e18bf5aeed07 early so that the bisect was able to differentiate between a bunch of “broken” commits which ended with:

+ venv/bin/pip install -e .
Traceback (most recent call last):
  File "venv/bin/pip", line 7, in <module>
    from pip import main
  File "/tmp/test/pip/tdir/venv/local/lib/python2.7/site-packages/pip/__init__.py", line 26, in <module>
    from pip.utils import get_installed_distributions, get_prog
  File "/tmp/test/pip/tdir/venv/local/lib/python2.7/site-packages/pip/utils/__init__.py", line 23, in <module>
    from pip.locations import (
  File "/tmp/test/pip/tdir/venv/local/lib/python2.7/site-packages/pip/locations.py", line 83, in <module>
    site_packages = sysconfig.get_python_lib()
AttributeError: 'module' object has no attribute 'get_python_lib'
git bisect start
git bisect good 9.0.3
git bisect bad HEAD
git bisect run ../bisect.sh

After the bisect run, it points at this:

904fcf1f177770a4eb05e0850d79265e4bc0907f is the first bad commit
commit 904fcf1f177770a4eb05e0850d79265e4bc0907f
Author: Donald Stufft <donald@stufft.io>
Date:   Sat Mar 18 13:32:10 2017 -0400

    Use sysconfig instead of distutils.sysconfig

:040000 040000 dfd417efac444008f5ca7e07f85de83168e0e6de 710942f93e7ce4df8553c8534b515a60aa2feb39 M	pip
bisect run success

CC @dstufft 904fcf1f177770a4eb05e0850d79265e4bc0907f

A further triage, the failure appears to come from a differing return value in dist_is_local here:

https://github.com/pypa/pip/blob/d67d98dd914e2ce80ece43594554f0a226558db0/src/pip/_internal/req/req_uninstall.py#L276

The difference appears to be the return values here:

$ venv/bin/python -c 'import sysconfig; print(sysconfig.get_path("purelib"))'
/tmp/test/venv/local/lib/python2.7/dist-packages

$ venv3/bin/python -c 'import sysconfig; print(sysconfig.get_path("purelib"))'
/tmp/test/venv3/lib/python3.5/site-packages

On Saturday, May 23, 2020 8:06:13 PM EDT Tzu-ping Chung wrote:

Just to confirm, has anyone in this thread tried to file an issue to Debian?

Since I’m the primary maintainer for virtualenv and pip in Debian right now, it wouldn’t make me any more aware of it than I am now.

Also, don’t assume the previous discussion is right. I tried a patch very similar to the linked pull request and it didn’t solve the problem. That may be on me for either not getting the change right or not testing correctly, but I’m not 100% sure the previous discussion is on the right path.

🤷 it used to work though is my point

I took a look a this on Debian stable as well as unstable/testing. Click is now python3 only so the original problem with that repository can’t occur. I tried the reproduction steps on python3 and it uninstalled fine.

I don’t know how much effort it’s worth fixing python2 stuff now, but if someone will provide another example where the problem still occurs I will take a look at it.