retire ofswiki
[iankelling.org] / technical-notes / setup.py-uninstall.md
diff --git a/technical-notes/setup.py-uninstall.md b/technical-notes/setup.py-uninstall.md
new file mode 100644 (file)
index 0000000..dc8d056
--- /dev/null
@@ -0,0 +1,44 @@
+## Unix-like
+
+Install over the existing installation with the same sources, recording installed files, then delete them.
+
+``` sh
+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.
+
+``` sh
+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
+
+* pip
+* python setup.py install bdist_rpm
+* python setup.py bdist_wininst
+* [official python recommendations](https://packaging.python.org/)
+
+This page is also at [stackoverflow answer](http://stackoverflow.com/a/25209129/14456).
+
+TODO: contribute this under https://wiki.python.org/moin/Distutils/Cookbook.