mlissner
mlissner

Reputation: 18166

How did I accidentally install two versions of a package using pip?

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.

Upvotes: 2

Views: 579

Answers (1)

Rafael
Rafael

Reputation: 1875

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

Upvotes: 1

Related Questions