views:

2782

answers:

6

I have installed a python package with python setup.py install.

How do I uninstall it?

+17  A: 

You need to remove all files manually, and also undo any other stuff that installation did manually.

If you don't know the list of all files, you can reinstall it with the --record option, and take a look at the list this produces.

Martin v. Löwis
I can't get this to work. Is there an example?
Clutch
Something like:`python setup.py install --record files.txt`And when you find out the list is complete:`cat files.txt | xargs rm -rf`
Michal Čihař
+2  A: 

Go to your python package directory and remove your .egg file, e.g.: In python 2.5(ubuntu): /usr/lib/python2.5/site-packages/

In python 2.6(ubuntu): /usr/local/lib/python2.6/dist-packages/

Works, unless the install installed files outside of the package, which some do, like setuptools that installs and easy_install command.
Lennart Regebro
Normally, if a package was installed using python setup.py as specified by the OP, there would not be an egg. OTOH, if there is one because easy_install was used, the documented way to uninstall packages is to use easy_install -m before deleting the egg file; otherwise, egg shells may be left behind in the easy-install.pth file.
Ned Deily
+4  A: 

The lazy way: simply uninstall from the Windows installation menu (if you're using Windows), or from the rpm command, provided you first re-install it after creating a distribution package.

For example,

python setup.py bdist_wininst
dist/foo-1.0.win32.exe

("foo" being an example of course).

RedGlyph
I don't know if I like it, but you get a point for orthogal thinking. :)
Lennart Regebro
To be honest, I'm not sure either hence "the lazy way" ;-) But I thought I'd mention it was possible to create more "standard" installer. It's strange the setup.py doesn't provide a clean way to remove packages though.
RedGlyph
Uninstalls require centralized registries of installed packages and it's files, and there isn't one. Discussions are ongoing on how to improve this story and it might be solved in Python 2.7/3.2 or 2.8/3.3 or so.
Lennart Regebro
That's what I thought. Well, it's good to know it might be sorted out soon, thanks the information!
RedGlyph
+1  A: 

Extending on what Martin said, recording the install output and a little bash scripting does the trick quite nicely. Here's what I do...

for i in $(less install.record); sudo rm $i; done;

And presto. Uninstalled.

seabass
A: 

Last answer helped me out so thanks for that. Not sure why I didn't think of it. Just a syntax correction though:

for i in $(less install.record); sudo rm $i; done;

should be:

for i in $(less install.record); do sudo rm $i; done;

otherwise you'll get a syntax error from bash. Also, be sure to change 'install.record' to whatever file you passed to your --record option. Not trying to be critical, just wanted to clarify in case someone who didn't know much about bash came across this post.

SomeGuy
A: 

Or more simply you could just do;

sudo rm $(cat install.record)

This works because the rm command takes a whitespace-seperated list of files to delete and your installation record is just such a list. Also, using "less" for this type of command could get you in big trouble depending on the local configuration.

nathan