96

Can you simply delete the directory from your python installation, or are there any lingering files that you must delete?

Hortitude
  • 13,638
  • 16
  • 58
  • 72

13 Answers13

46

It varies based on the options that you pass to install and the contents of the distutils configuration files on the system/in the package. I don't believe that any files are modified outside of directories specified in these ways.

Notably, distutils does not have an uninstall command at this time.

It's also noteworthy that deleting a package/egg can cause dependency issues – utilities like easy_install attempt to alleviate such problems.

Baum mit Augen
  • 49,044
  • 25
  • 144
  • 182
cdleary
  • 69,512
  • 53
  • 163
  • 191
  • 4
    Can you please update this to directly address the lingering files part of the question? – S.Lott Dec 31 '08 at 11:26
  • I thought I did -- no files are created outside of the directories specified by the distutils configuration and install flags, so any "lingering" files will exist in these directories. It varies from package to package. – cdleary Dec 31 '08 at 21:53
  • 2
    @cdleary: thanks, but, I was hoping you'd simply clarify and strengthen your answer, not add a long comment thread. – S.Lott Jan 01 '09 at 00:37
  • 2
    @S.Lott: Sorry, but I don't know which part of the answer you want clarification on -- can you be more specific? – cdleary Jan 01 '09 at 02:23
  • 1
    **[msg139773](http://bugs.python.org/issue4673#msg139773) Date: 2011-07-04 14:35 distutils2/packaging now provides a remove function and a pysetup remove command.** – Edward Jan 28 '16 at 17:24
20

The three things that get installed that you will need to delete are:

  1. Packages/modules
  2. Scripts
  3. Data files

Now on my linux system these live in:

  1. /usr/lib/python2.5/site-packages
  2. /usr/bin
  3. /usr/share

But on a windows system they are more likely to be entirely within the Python distribution directory. I have no idea about OSX except it is more likey to follow the linux pattern.

Ali Afshar
  • 40,967
  • 12
  • 95
  • 109
14

Another time stamp based hack:

  1. Create an anchor: touch /tmp/ts
  2. Reinstall the package to be removed: python setup.py install --prefix=<PREFIX>
  3. Remove files what are more recent than the anchor file: find <PREFIX> -cnewer /tmp/ts | xargs rm -r
Shantha Kumara
  • 3,272
  • 4
  • 40
  • 52
maximk
  • 188
  • 1
  • 4
  • 3
    -1. I don't like the `| xargs rm -r`. I recommend going over each file *manually*. On ext4 (and other file systems), this `find` is going to list all *folders* too. If your prefix was `/usr`, you're **going to delete `/usr/*`**. – Mateen Ulhaq May 18 '19 at 05:56
9

Yes, it is safe to simply delete anything that distutils installed. That goes for installed folders or .egg files. Naturally anything that depends on that code will no longer work.

If you want to make it work again, simply re-install.

By the way, if you are using distutils also consider using the multi-version feature. It allows you to have multiple versions of any single package installed. That means you do not need to delete an old version of a package if you simply want to install a newer version.

Salim Fadhley
  • 22,020
  • 23
  • 75
  • 102
5

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

/usr/local/lib/python2.7/

And simply remove the associated folder and file, if there is one!

Hydrox24
  • 340
  • 3
  • 9
5

install --record + xargs rm

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

removes all files and but leaves empty directories behind.

That is not ideal, it should be enough to avoid package conflicts.

And then you can finish the job manually if you want by reading files.txt, or be braver and automate empty directory removal as well.

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.

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
4

If this is for testing and/or development purposes, setuptools has a develop command that updates every time you make a change (so you don't have to uninstall and reinstall every time you make a change). And you can uninstall the package using this command as well.

If you do use this, anything that you declare as a script will be left behind as a lingering file.

Jason Baker
  • 192,085
  • 135
  • 376
  • 510
4

for Python in Windows:

python -m pip uninstall "package_keyword"
uninstall **** (y/n)?
pacholik
  • 8,607
  • 9
  • 43
  • 55
3

For Windows 7,

Control Panel --> Programs --> Uninstall

, then

choose the python package to remove.

b_dev
  • 2,568
  • 6
  • 34
  • 43
2

I just uninstalled a python package, and even though I'm not certain I did so perfectly, I'm reasonably confident.

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

Luckily, I've got python installed under /opt/Python-2.6.1; if I had been using the Python that comes with my Linux distro, I'd have had to scour all of /usr, which would have taken a long time.

Then I just examined that list, and noted with relief that all the stuff that I wanted to nuke 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-x.x.x_blah-py2.6.egg-info.

So I just deleted those.

Here's how I got the date-sorted list of files:

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

(I think that's got to be GNU "find", by the way; the flavor you get on OS X doesn't know about "-printf '%T@'")

I use that all the time.

offby1
  • 6,767
  • 30
  • 45
1

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

  • {packageName}
  • {packageName}-{version}-info

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

  • 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 is your site-packages:

python -m site
Lynne
  • 454
  • 7
  • 16
1

What it worked for me on Windows 10 and using Python for Windows version 3.96 was to just erase the folder containing the module inside the site-package folder. In my case this was located at: C:\Python396\Lib\site-packages. After this a pip list does not show the module that I wanted to delete anymore.

David
  • 121
  • 4
-1

ERROR: flake8 3.7.9 has requirement pycodestyle<2.6.0,>=2.5.0, but you'll have pycodestyle 2.3.1 which is incompatible. ERROR: nuscenes-devkit 1.0.8 has requirement motmetrics<=1.1.3, but you'll have motmetrics 1.2.0 which is incompatible. Installing collected packages: descartes, future, torch, cachetools, torchvision, flake8-import-order, xmltodict, entrypoints, flake8, motmetrics, nuscenes-devkit Attempting uninstall: torch Found existing installation: torch 1.0.0 Uninstalling torch-1.0.0: Successfully uninstalled torch-1.0.0 Attempting uninstall: torchvision Found existing installation: torchvision 0.2.1 Uninstalling torchvision-0.2.1: Successfully uninstalled torchvision-0.2.1 Attempting uninstall: entrypoints Found existing installation: entrypoints 0.2.3 ERROR: Cannot uninstall 'entrypoints'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

Then I type:

conda uninstall entrypoints pip install --upgrade pycodestyle pip install nuscenes-devkit

Done!

goodpen
  • 1
  • 1