2

Hopefully there's a reasonable explanation, but I just ran into a weird issue where I somehow had multiple versions of the same package installed on my server.

I only ever install using pip. I upgrade by running:

pip install --upgrade -r requirements.txt

However, if you look at the link above (and summarized below), you'll see that I was able to uninstall the same package twice in a row using pip. First it uninstalled version 0.15.3 (the version I wanted installed), and then it uninstalled an older version that shouldn't have been there.

↪ ../.virtualenvs/courtlistener/bin/pip uninstall django_filter
Uninstalling django-filter-0.15.3:
Proceed (y/n)? y
  Successfully uninstalled django-filter-0.15.3

# Great. It's uninstalled.


↪ ../.virtualenvs/courtlistener/bin/pip install django_filter
Requirement already satisfied: django_filter in /var/www/.virtualenvs/courtlistener/lib/python2.7/site-packages

# HUH?!

↪ sudo ../.virtualenvs/courtlistener/bin/pip uninstall django_filter
Uninstalling django-filter-0.11.0:
Proceed (y/n)? y
  Successfully uninstalled django-filter-0.11.0

I want to understand how this happened so I can be sure it doesn't happen again. It was a real pain to sort out.

mlissner
  • 17,359
  • 18
  • 106
  • 169

1 Answers1

1

Unfortunately, it happens sometimes. Just found two possibilities (but could have happen in a different way for you).

pip bug

python-pip (1.0-1build1) of Ubuntu 12.04 had a bug which caused packages not to be removed.

pip is not uninstalling packages (check Oz123 Answer). His recommendation was not use distribution pip. Instead, use pip from upstream.

easy_install

Just tested easy_install, and it did not remove the package:

# Tested on docker with python 2
# docker run --rm -it python:2 bash

pip install django_filter==0.11.0
pip install django_filter==0.15.3
find / -name django_filters -type d
# Prints
# /usr/local/lib/python2.7/site-packages/django_filters
pip uninstall django_filter

easy_install django_filter==0.11.0
easy_install django_filter==0.15.3
find / -name django_filters -type d
# Prints
# /usr/local/lib/python2.7/site-packages/django_filter-0.11.0-py2.7.egg/django_filters
# /usr/local/lib/python2.7/site-packages/django_filter-0.15.3-py2.7.egg/django_filters
pip uninstall django_filter
pip uninstall django_filter

In this case, the recommendation is not use easy_install.

Why use pip over easy_install? (the accepted answer has a lot of more reasons for this).

Community
  • 1
  • 1
Rafael
  • 1,835
  • 3
  • 18
  • 26
  • I'm using version 9.0.1 of pip in my virtualenv, which is the latest version. Hmph. Any other theories? – mlissner May 09 '17 at 18:36
  • Sorry, but i don't =/. Didn't found out other cases of this bug. I think you were very unlucky on this bug. – Rafael May 10 '17 at 01:23