7

I have installed a python application with this setup.py:

#!/usr/bin/env python

from distutils.core import setup
from libyouandme import APP_NAME, APP_DESCRIPTION, APP_VERSION, APP_AUTHORS, APP_HOMEPAGE, APP_LICENSE

setup(
    name=APP_NAME.replace(" ","-").lower(),
    version=APP_VERSION,
    description=APP_DESCRIPTION,
    author="John G",
    author_email="xxx@gmail.com",
    url=APP_HOMEPAGE,
    license=APP_LICENSE,
    scripts=["youandme.py"],
    packages=["libyouandme"],
    data_files=[
        ('share/applications', ['youandme.desktop']),
        ('usr/share/icons/hicolor/16x16/apps', ['icons/hicolor/16x16/apps/you.png']),
        ('usr/share/icons/hicolor/22x22/apps', ['icons/hicolor/22x22/apps/you.png']),
        ('usr/share/icons/hicolor/48x48/apps', ['icons/hicolor/48x48/apps/you.png'])],
)

How can I remove this application from my ubuntu machine ?

Do I can do this with distutils ?

xRobot
  • 25,579
  • 69
  • 184
  • 304
  • possible duplicate: http://stackoverflow.com/questions/402359/how-do-you-uninstall-a-python-package-that-was-installed-using-distutils – mouad Oct 23 '10 at 18:26

5 Answers5

6

Install the checkinstall Ubuntu package. checkinstall monitors the installation procedure and creates a deb package. This lets you use regular package management commands to remove the software.

First, reinstall the candidate python module/package using checkinstall. Change directory to the directory containing the setup.py file of the candidate python module/package:

cd <PACKAGE_NAME>

Then:

sudo checkinstall -D --fstrans=no python setup.py install

This creates a .deb package, and installs the python module again. You'll be asked a few questions. The default answers should be fine. (But you might change the "name" of the .deb package, when the setup.py file is in a subdirectory of the python module, for example the "source" subdirectory.)

(The saved .deb package now captures how the python package installed itself, and dpkg can remove the python package.)

Then immediately remove the module:

sudo dpkg -r <PACKAGE_NAME>

PS. I've heard that some installation programs are not compatible with checkinstall, though I've never run into any problems myself.

bootchk
  • 1,926
  • 17
  • 14
unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677
4

Since pip 8.0.0 running pip uninstall <package> does not work when <package> is something that was pre-installed by the OS (probably with python setup.py install).

The error message is:

Detected a distutils installed project ('<package>') which we cannot uninstall. The metadata provided by distutils does not contain a list of files which have been installed, so pip does not know which files to uninstall.

Instead of using pip to uninstall these packages you need to use the OS package manager instead.

So on Ubuntu: sudo apt-get remove python-<package> would remove it.

I've found two packages that have this problem: httplib2 and six, and the above trick helped me get by that error. Hope that others find this useful.

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Emil Stenström
  • 13,329
  • 8
  • 53
  • 75
4

AFAIK only pip allows to uninstall python modules, so if you don't have it installed, you can install it with

sudo easy_install pip

and then use pip to uninstall your module

sudo pip uninstall <module_name>

where module_name is the value passed in the name argument of the setup function.

Edit: just saw you tagged your question with "python-3.x", and there is no 3.x version for pip yet, so if you need to uninstall a python3.x module, this answer doesn't fit.

mdeous
  • 17,513
  • 7
  • 56
  • 60
  • i think pip can't uninstall package that was installed with setup.py install or develop see this : http://pip.openplans.org/ section uninstall – mouad Oct 23 '10 at 18:23
  • @singularity: hmm, strange, i installed many homemade libs using `python setup.py install` and i've always been able to remove them with pip, even if pip's documentation seems to tell i shouldn't have been able to. I might have missed something... – mdeous Oct 23 '10 at 18:45
  • yes it sound weird , because for getting pip uninstall to work, pip create a meta-data for each installed package so it can track all the files that have been created , so like that it can remove them when you can pip uninstall , but distuils don't do this, and know like i said in my answer distutils2 can do this as well but they never program to add this feature to the distutils, you can see it here: http://bugs.python.org/issue4673 – mouad Oct 23 '10 at 19:23
2

The disutils version 1 don't support uninstall command and i have also included a link for you in the comment to see it, but just for info disutils2 now support uninstall command , they have been working on it in the past GSoC, you can check this link

The only way for you to "uninstall" your package is by removing all your file by hand, i can see that you have some files in /usr/share .. , i don't know if you know this already but you can use python install.py develop when developing your module , it will make change and remove easily .

mouad
  • 67,571
  • 18
  • 114
  • 106
0

I discovered that when installing a new version of a library, distutils did not delete old modules that were no longer part of the package. It only replaced the old ones. Here's a simple example of how I uninstalled the old files before running setup. It's not a complete and perfect uninstall per se, but it might help those of you with the same needs, or send you down a functional workaround path.

from distutils.core import setup
import distutils.sysconfig
from os import path
from shutil import rmtree

PACKAGE_NAME = "MyPackage"

# If found, uninstall a prior version.
# This will delete any modules that are no longer in use.
targetDirPath = path.join( distutils.sysconfig.get_python_lib(), PACKAGE_NAME )
if path.exists( targetDirPath ) :
    try :
        rmtree( targetDirPath )
        print "Removed prior package at: %s" % (targetDirPath,)
    except Exception as e:    
        print "Failed to remove prior package at: %s" % (targetDirPath,)
        print e

setup(name=PACKAGE_NAME,
      version='1.2.3',
      packages=['subpackage'] )
BuvinJ
  • 10,221
  • 5
  • 83
  • 96