54

I've installed python 2.6 from source, and somehow later mistakenly installed another python 2.6 from a package manager too.

I can't find a way to uninstall a python that was built from source, is this possible/easy?

Running ubuntu 10.04.

Dimitris Fasarakis Hilliard
  • 150,925
  • 31
  • 268
  • 253
Ian P
  • 1,512
  • 3
  • 15
  • 18

6 Answers6

33

You can use checkinstall to remove Python. The idea is:

  1. Install checkinstall
  2. Use checkinstall to make a deb of your Python installation
  3. Use dpkg -r to remove the deb.

See this post for more details.

PS. Note that Ubuntu must always have at least one installation of Python installed, or else major pieces of your OS stop working. Above, I'm assuming it's safe to remove the Python built from source, without removing the Python that was installed by the package manager.

PPS. If you accidentally erase all Python installations from your Ubuntu machine, all is not lost. Instructions on how to recover from this situation can be found here.

unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677
  • 2
    Can you elaborate on the dpkg -r command? I am in the Python source directory and when I run that command it doesn't work. It also says the deb file isn't install even after I run dpkg -i with the deb file. – rplankenhorn Sep 21 '16 at 20:33
  • Didn't work for me either. It says I need to use `dpkg -r python` to uninstall, which attempts to uninstall python completely! – andyhasit Dec 15 '16 at 16:54
  • 2
    Be especially careful, when you create .deb of your installation (step 2 in answer) - check the name of created package. In my case I tried to remove python 3.6.3 package. By default checkinstall created deb with name *python*. I ran `dpkg -r`, but it said, that package was not installed, I tried sequence of `dpkg -i` `dpkg -r`. That sequence overwrite contents of `/var/lib/dpgk/status` and now I got python of version of 3.6.3 and lots of python 2.* dependencies were reported broken by `apt-get check`. I had to change contents of dpkg status file manually to recover. – Mikalai Parafeniuk Oct 05 '17 at 10:06
  • I find with python 3.6.9 this works but dpkg or apt doesn't clean-up all the site packages - because of the way ensurepip is called from the python makefile. It still does 90% of the work for you, but I find I have to manually purge the correct site-packages folder for any reinstallation to reinstall pip. – Phil Nov 20 '20 at 18:07
4

I did the following and reinstall using 'make install' and it worked.

whereis python3.6
rm -rf /usr/local/lib/python3.6
rm -rf /usr/local/bin/python3.6*
make install
das
  • 41
  • 1
0

Have you looked into make uninstall I believe this should work for you, assuming you have the python 2.6 source and the make file has uninstall available (it should).

http://www.linuxquestions.org/questions/linux-newbie-8/source-uninstall-with-make-uninstall-howto-230225/

Julio
  • 2,261
  • 4
  • 30
  • 56
  • 1
    Running ./configure then `make uninstall' returns `make: *** No rule to make target `uninstall'. Stop.'. Maybe i downloaded the wrong python version? Edit: tried it with the correct version, same result. – Ian P Aug 23 '10 at 02:42
  • Sounds like the make file doesn't have any reference for uninstall. It's possible that your python installation created a setup.py file, in which case you can do a: setup.py uninstall Here are a few links that may be useful: http://serverfault.com/questions/50323/uninstall-python-packages-built-from-source http://www.linuxforums.org/forum/redhat-fedora-linux-help/138085-how-uninstall-python.html – Julio Aug 23 '10 at 02:45
0

In the future it may be prudent to use sudo checkinstall.

Dimitris Fasarakis Hilliard
  • 150,925
  • 31
  • 268
  • 253
maletor
  • 7,072
  • 7
  • 42
  • 63
  • 2
    Why? What is it? A little bit more info would be helpful. – tread Jul 20 '20 at 07:16
  • This seems to be a minimal version of @unutbu's answer, which did not yet exist at the time. It was perhaps marginally useful at the time, but I am now downvoting this as redundant and obscure. – tripleee Jul 06 '21 at 08:58
  • Not readily available on all platforms, unfortunately. – AdamC Feb 03 '23 at 16:20
-2

Below command removed all the things it installed for me.

make -n install
ExploringApple
  • 1,348
  • 2
  • 17
  • 30
  • 1
    It lists all the things `make install` would have installed. You still have to remove the actual files. – danijar Jan 15 '18 at 17:37
  • 1
    think you can probably do `make -n [install|altinstall] | xargs rm` – Dash Winterson Apr 24 '19 at 12:30
  • No, the output form `make -n` are the *commands* it would run; you would have to understand and parse the output to extract the file locations. A line like `install build/* /usr/local/bin` does not reveal exactly which files are being copied, anyway; if you haven't changed the source directory, you can figure out what it did, but this is by no means trivial. Also, the `-n` option can actually change what `make` thinks it needs to do. – tripleee Jul 06 '21 at 08:51
-4

Do you still have the source directory where you compiled Python before? If so, you can CD into that directory and run sudo make uninstall.

If you don't have it still, you could re-create it by going through the build steps again--download, extract, configure, and make--but end with sudo make uninstall instead of sudo make install, of course.

ewall
  • 27,179
  • 15
  • 70
  • 84