How to remove a python package that was installed using distutils?

Can you just remove the directory from your python installation or any lingering files you have to remove?

+82
python
Dec 31 '09 at 5:26
source share
11 answers

It depends on the parameters you pass for install and on the contents of the distutils configuration files on the system / in the package. I do not believe that any files are modified outside of the directories indicated by these methods.

Notably, distutils does not currently have a delete command .

It should also be noted that package / egg removal can cause dependency problems - utilities like easy_install try to alleviate such problems.

+39
Dec 31 '09 at 7:00
source share

Three things that are installed that you need to remove:

  • Packages / Modules
  • Scenarios
  • Data files

Now on my Linux system they live in:

  • /usr/lib/python2.5/site-packages
  • / Usr / bin
  • / USR / share

But on Windows, they are most likely completely in the Python distribution directory. I have no idea about OSX, except that it looks more like a linux sample.

+18
Dec 31 '09 at 17:31
source share

Another hack based timestamp:

  • Create Anchor: touch /tmp/ts
  • Reinstall the package to be removed: python setup.py install --prefix=<PREFIX>
  • Delete files that are more recent than the binding file: find <PREFIX> -cnewer /tmp/ts | xargs rm -r find <PREFIX> -cnewer /tmp/ts | xargs rm -r
+15
Dec 12 '11 at 7:27
source share

Yes, it’s safe to just uninstall everything distutils has installed. This applies to installed folders or .egg files. Naturally, everything that depends on this code will no longer work.

If you want it to work again, just reinstall.

By the way, if you are using distutils, also consider using a function with multiple versions. This allows you to have multiple versions of any installed package. This means that you do not need to remove the old version of the package if you just want to install a newer version.

+7
Jan 01 '09 at 20:06
source share

If this is for testing and / or development purposes, setuptools has develop , which is updated every time you make changes (so you don’t need to uninstall and reinstall every time you make changes). And you can also remove the package using this command.

If you use this, everything you declare as a script will remain as a lingering file.

+4
Dec 31 '09 at 17:24
source share

In ubuntu 12.04, I found that the only place you need to look at the default is under

 /usr/local/lib/python2.7/ 

And just delete the linked folder and file if there is one!

+4
Jul 31 '12 at 21:24
source share

I just uninstalled the python package, and although I'm not sure I did it perfectly, I'm pretty sure.

I started by getting a list of all python-related files sorted by date, based on the assumption that all the files in my package will have more or less the same timestamp, and no other files will be.

Fortunately, I have python installed under /opt/Python-2.6.1 ; if I used Python, which comes with my Linux distribution, I would have to comb through all /usr , which would take a lot of time.

Then I just looked at this list and was relieved to note that all the materials I wanted to use consisted of one directory /opt/Python-2.6.1/lib/python2.6/site-packages/module-name/ and one file /opt/Python-2.6.1/lib/python2.6/site-packages/module-xxx_blah-py2.6.egg-info .

So I just deleted them.

Here's how I got the file list sorted by date:

find "$@" -printf '%T@ ' -ls | sort -n | cut -d\ -f 2-

(I think that, by the way, GNU "found", the taste that you get in OS X does not know about "-printf"% T @ ")

I use it all the time.

+2
May 30 '09 at
source share

For windows 7

Control Panel → Programs → Delete

then

select the python package to uninstall.

+2
Dec 24 '10 at 3:50
source share

install --record + install --record xargs rm

 sudo python setup.py install --record files.txt xargs sudo rm -rf < files.txt 

deletes all files and leaves empty directories behind.

This is not ideal; it should be enough to avoid packet conflicts.

And then you can finish the job manually if you want by reading files.txt , or be bolder and automate the removal of empty directories.

A safe helper would be:

 python-setup-uninstall() ( sudo rm -f files.txt sudo python setup.py install --record files.txt && \ xargs rm -rf < files.txt sudo rm -f files.txt ) 

Tested in Python 2.7.6, Ubuntu 14.04.

+2
Apr 27 '17 at 7:03 on
source share

for Python on Windows:

 python -m pip uninstall "package_keyword" uninstall **** (y/n)? 
+1
May 27 '17 at 13:05
source share

On Mac OSX, manually delete these 2 directories in your pathToPython / site-packages / :

  • {package name}
  • {PackageName} - {version} -info

for example, to remove pyasn1 , which is the distutils project installed:

  • rm -rf lib / python2.7 / site-packages / pyasn1
  • rm -rf lib / python2.7 / site-packages / pyasn1-0.1.9-py2.7.egg -info

To find out where your site packages are:

 python -m site 
0
Jun 25 '18 at 19:53
source share



All Articles