Uninstall python built from source?
Solution 1
You can use checkinstall to remove Python. The idea is:
- Install checkinstall
- Use checkinstall to make a deb of your Python installation
- 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
Ian P
Updated on July 09, 2022Comments
-
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 over 13 yearsRunning ./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 over 13 yearsSounds 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 over 7 yearsCan 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 over 7 yearsDidn't work for me either. It says I need to use
dpkg -r python
to uninstall, which attempts to uninstall python completely! -
Mikalai Parafeniuk over 6 yearsBe 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 ofdpkg -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 byapt-get check
. I had to change contents of dpkg status file manually to recover. -
danijar over 6 yearsIt lists all the things
make install
would have installed. You still have to remove the actual files. -
Dash Winterson about 5 yearsthink you can probably do
make -n [install|altinstall] | xargs rm
-
tread almost 4 yearsWhy? What is it? A little bit more info would be helpful.
-
Phil over 3 yearsI 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 almost 3 yearsNo, 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 likeinstall 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 whatmake
thinks it needs to do. -
tripleee almost 3 yearsThis 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.