Uninstall python built from source?

68,683

Solution 1

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.

Solution 2

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
Share:
68,683
Ian P
Author by

Ian P

Updated on July 09, 2022

Comments

  • Ian P
    Ian P almost 2 years

    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.

  • Ian P
    Ian P over 13 years
    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.
  • Julio
    Julio over 13 years
    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: serverfault.com/questions/50323/… linuxforums.org/forum/redhat-fedora-linux-help/…
  • rplankenhorn
    rplankenhorn over 7 years
    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.
  • andyhasit
    andyhasit over 7 years
    Didn't work for me either. It says I need to use dpkg -r python to uninstall, which attempts to uninstall python completely!
  • Mikalai Parafeniuk
    Mikalai Parafeniuk over 6 years
    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.
  • danijar
    danijar over 6 years
    It lists all the things make install would have installed. You still have to remove the actual files.
  • Dash Winterson
    Dash Winterson about 5 years
    think you can probably do make -n [install|altinstall] | xargs rm
  • tread
    tread almost 4 years
    Why? What is it? A little bit more info would be helpful.
  • Phil
    Phil over 3 years
    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.
  • tripleee
    tripleee almost 3 years
    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
    tripleee almost 3 years
    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.