Uninstalling setup.py install

From Opinionated Free Software Wiki
Jump to: navigation, search

Unix (linux, mac, etc)

Install over the existing installation with the same sources, recording installed files, then delete them.

sudo python setup.py install --record files.txt
# inspect files.txt to make sure it looks ok. Then in bash:
tr '\n' '\0' < files.txt | xargs -0 sudo rm -f --

Windows

Install on top of the existing installation with a windows installer, then add-remove programs to uninstall.

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

Use other methods which fully support uninstall when available

Uninstalling setup.py install has some inherent problems, which usually aren't a problem:

  • Files which a different package also depends on will be removed by uninstall
  • Can't remove installed directories. --record only records non-directory files.
  • If a file is installed which includes a newline, the command this page recommends will fail. This won't happen except for a rare bug or a malicious program. We could overcome this by using bdist_dumb, then removing the files found in the archive which that command builds. However, I'm no more confident of that command not having a bug or edge case in which it would produce different files than a normal install than I am of a package having a file with a newline in it.

Alternatives (this list is not comprehensive):

Comparison to other answers

This page has been added as a stackoverflow answer. Feel free to vote on it.

The #1 and best result from google's first page of answers is this this stackoverflow answer with ~250 votes which doesn't address windows, doesn't address the inherint flaws listed above, and has serious correctable flaws:

  • the -r in rm -rf is unnecessary and at worst could delete things you don't want to.
  • If a file is installed which includes spaces or other special characters, the xargs command will fail, and delete any files/directories which matched the individual words.
  • Minor problem: No mention of permissions, root is often needed

The #2 stackoverflow answer is unreliable, often simply does not work.

todo for this page