38

Background

I'm working on an academic project to (basically) analyze some "who follows whom" graphs and wanted to get some real data (by building some small datasets) from Twitter using one of the Python Twitter API packages in order to test some ideas I have.

I was a bit careless and installed two packages:

a) python-twitter0.8.2 (http://pypi.python.org/pypi/python-twitter/0.8.2)

b) twitter1.9.1 (http://pypi.python.org/pypi/twitter/1.9.1)

(a) is called python-twitter in pypi, and (b) is called twitter, so that's how I'll refer to them.

Both of these are called by import twitter in the Python interpreter, but when I write that line, I always get the twitter one (if I can figure out how to use the python-twitter one, I'll be able to proceed, but will still have the same underlying problem).


Problem

Since I don't need the twitter package, I decided to uninstall it with pip:

$ sudo pip uninstall twitter

which gives the output:

Uninstalling twitter:
Proceed (y/n)? y
  Successfully uninstalled twitter

(actually, I tried the same thing with python-twitter and got a similar response).

However, when running pip freeze, both of these packages show up on the installed list! In fact, I can still use the import twitter command successfully in the interpreter. Clearly the packages have not been uninstalled. What I would love to know is how to uninstall them!


Other Info

I'm using Python 2.7 and Ubuntu 12.04

When running IDLE instead of the shell interpreter, and I type help('modules'), neither twitter nor python-twitter shows up in the list. When typing help('modules') into the shell interpreter, I get a segmentation fault error, and the interpreter crashes. Here's the error:

>>> help('modules')

Please wait a moment while I gather a list of all available modules...

/usr/lib/python2.7/dist-packages/gobject/constants.py:24: Warning:
  g_boxed_type_register_static: assertion `g_type_from_name (name) == 0' failed
  import gobject._gobject
/usr/lib/python2.7/dist-packages/gtk-2.0/gtk/__init__.py:40: Warning:
  g_boxed_type_register_static: assertion `g_type_from_name (name) == 0' failed
  from gtk import _gtk

** (python:2484): CRITICAL **: pyg_register_boxed: assertion `boxed_type != 0' failed
/usr/lib/python2.7/dist-packages/gtk-2.0/gtk/__init__.py:40: Warning: cannot register
existing type `GdkDevice'
  from gtk import _gtk
/usr/lib/python2.7/dist-packages/gtk-2.0/gtk/__init__.py:40: Warning: g_type_get_qdata: 
assertion `node != NULL' failed
  from gtk import _gtk
Segmentation fault (core dumped)

Why other questions have not resolved this for me:

I looked at the similar post at pip freeze lists uninstalled packages and am not having the same issues.

$ sudo which pip
/usr/bin/pip
$ which pip
/usr/bin/pip

which is the same output. In addition, $ sudo pip freeze gives the same output as $ pip freeze.

Any help is very much appreciated!

ndmeiri
  • 4,979
  • 12
  • 37
  • 45
David
  • 385
  • 1
  • 3
  • 8

5 Answers5

58

You can always manually delete the packages; you can run:

sudo rm -rf /usr/local/lib/python2.7/dist-packages/twitter

to remove that package from your dist-packages directory. You may have to edit the easy-install.pth file in the same directory and remove the twitter entry from it.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • Thanks! Should I also remove `twitter-1.9.1-py2.7.egg-info`, `twitter.py`, and `twitter.pyc` or is removing the directory enough? – David Jan 28 '13 at 23:12
  • Yes, remove all of those; and the `python-twitter` egg info if it is there. Remove both `twitter` and `python-twitter` from the `easy-install.pth` file (grep for the names in any other `.pth` file if there are any). – Martijn Pieters Jan 28 '13 at 23:14
  • @DavidBodow: Did that fix your problem? – Martijn Pieters Jan 28 '13 at 23:48
  • Yes; thank you. Still curious as to what went wrong with pip, but the problem is fixed now. – David Jan 29 '13 at 16:15
  • 6
    Yeah. This just happened to me. Does anyone know what causes this? – Brett Widmeier May 15 '14 at 14:54
  • 2
    @BrettWidmeier, the cause of the problem is some modifications done in the debian version of pip which is also the source for the ubuntu package. See my answer below. – oz123 Nov 17 '14 at 09:21
  • 1
    Note that some packages on the Raspberry Pi are /usr/lib/python and not /usr/local/lib/python – Danny Staple Jan 08 '21 at 21:58
  • 1
    @DannyStaple: the location of your Python will vary on exactly how you installed Python and your distribution. Use `python -m site` to have Python tell you where it looks for packages (look for the `site-packages` entry in the `sys.path` list). – Martijn Pieters Jan 09 '21 at 16:03
15

While Martin's solution works, as a work around, it does not provide a direct answer. Ubuntu's pip version for your Ubuntu version (12.04) is:

 python-pip (1.0-1build1)

This is also the same version for Debian Wheezy. This version has a weired bug, which causes packages not to be removed.
If you obtain pip from upstream using the script get-pip.py you will have a fixed version of pip which can remove pacakges (as of now v. 1.5.6).

update

Python's pip is really a fast moving target. So using Debian's or Ubuntu's pip is guaranteed to have bugs. Please don't use those distribution's pip. Instead install pip from upstream.

If you would like to register pip installed packages as system packages I really recommend that you also use stdeb.

oz123
  • 27,559
  • 27
  • 125
  • 187
  • 4
    you can get `get-pip.py` here: http://pip.readthedocs.org/en/latest/installing.html – hitzg Nov 19 '14 at 10:16
  • A couple of links for a deeper insight of this never-ending (at least, until Ubuntu 14.10) story: [Debian bug report log](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=751827) and [bug confirmed for Ubuntu Utopic (14.10)](https://bugs.launchpad.net/ubuntu/+source/python-pip/+bug/1392288) (confirmed also by my personal experience). – help_asap Apr 23 '15 at 10:59
4

I was facing difficulty while upgrading a package because pip was not able to uninstall it successfully. I had to delete the .egg-info and the folder as well in /usr/lib/python2.7/dist-packages and then I tried to install with --upgrade and it worked.

Wahib Ul Haq
  • 4,185
  • 3
  • 44
  • 41
3

For me, it was due to the fact that I was running pip freeze, which gave me different results than sudo pip freeze.

Since I was uninstalling using sudo, it was not uninstalling it in the "non-sudo" session. Uninstalling without sudo fixed that.

ndmeiri
  • 4,979
  • 12
  • 37
  • 45
  • While this did not directly solve my issue, it did remind me that `pip3 install` is not necessarily equivalent to `sudo pip3 install`, which indirectly helped me solve my issue. – ndmeiri Apr 18 '18 at 22:08
1

In my case (moving pyusb 0.4x to 1.0x), removing the old package with apt-get remove python-usb and manually installing the manually downloaded package via python setup.py worked. Not pretty, but working.

Jasper
  • 11
  • 1