The following commands will remove your make altinstall-ed python:
rm -f /usr/local/bin/python2.7
rm -f /usr/local/bin/pip2.7
rm -f /usr/local/bin/pydoc
rm -rf /usr/local/include/python2.7
rm -f /usr/local/lib/libpython2.7.a
rm -rf /usr/local/lib/python2.7
You might also have to do
rm -f /usr/local/share/man/python2.7.1
rm -rf /usr/local/lib/pkgconfig
rm -f /usr/local/bin/idle
rm -f /usr/local/bin/easy_install-2.7
Although make altinstall has served me well if the "system python" has a different major.minor number from the one you install, it doesn't work that well if only the micro number (the third position) differs. That number is excluded from the installed binary, and you end up with two versions pythonX.Y. This was always a problem but once distributions started shipping with system utilities based on 2.7.X this problem has been more severe as 2.7 is supposed to be the last of the Python2 series.
IMO the best approach to solve this problem is to prevent it from becoming one: configure python to install in a directory not used by any other python. On my system they go under /opt/python/X.Y.Z.
To use any of the Pythons installed there you use [virualenv][1] to make a new environment:
virtualenv --python=/opt/python/2.7.9/bin/python2.7 venv
source venv/bin/activate
or use [virtualenvwrapper][2]. I have some aliases for the latest versions in the series I work with.
If you are using tox for testing against multiple versions (you should) the following alias will help it find the various version:
alias tox='PATH=/opt/python/2.7.9/bin:/opt/python/2.6.9/bin:/opt/python/3.4.3/bin:/opt/python/3.3.6/bin:/opt/python/3.5-dev/bin:$PATH tox'
(these are currently the latest versions, I use a slightly different setup by maintaining links from /opt/python/2.7 to the latest /opt/python/2.7.9, and for the other minor numbers as well, within the process for downloading, building and installing a new python version)
These installs are never used directly. They are always used as the basis for virtualenv environments only, hence I don't care that they are not in my normal PATH.
The following commands will remove your make altinstall-ed python:
rm -f /usr/local/bin/python2.7
rm -f /usr/local/bin/pip2.7
rm -f /usr/local/bin/pydoc
rm -rf /usr/local/include/python2.7
rm -f /usr/local/lib/libpython2.7.a
rm -rf /usr/local/lib/python2.7
You might also have to do
rm -f /usr/local/share/man/python2.7.1
rm -rf /usr/local/lib/pkgconfig
rm -f /usr/local/bin/idle
rm -f /usr/local/bin/easy_install-2.7
Although make altinstall has served me well if the "system python" has a different major.minor number from the one you install, it doesn't work that well if only the micro number (the third position) differs. That number is excluded from the installed binary, and you end up with two versions pythonX.Y. This was always a problem but once distributions started shipping with system utilities based on 2.7.X this problem has been more severe as 2.7 is supposed to be the last of the Python2 series.
IMO the best approach to solve this problem is to prevent it from becoming one: configure python to install in a directory not used by any other python. On my system they go under /opt/python/X.Y.Z.
To use any of the Pythons installed there you use [virualenv][1] to make a new environment:
virtualenv --python=/opt/python/2.7.9/bin/python2.7 venv
source venv/bin/activate
or use [virtualenvwrapper][2]. I have some aliases for the latest versions in the series I work with.
If you are using tox for testing against multiple versions (you should) the following alias will help it find the various version:
alias tox='PATH=/opt/python/2.7.9/bin:/opt/python/2.6.9/bin:/opt/python/3.4.3/bin:/opt/python/3.3.6/bin:/opt/python/3.5-dev/bin:$PATH tox'
(these are currently the latest versions, I use a slightly different setup by maintaining links from /opt/python/2.7 to the latest /opt/python/2.7.9, and for the other minor numbers as well, within the process for downloading, building and installing a new python version)
These installs are never used directly. They are always used as the basis for virtualenv environments only, hence I don't care that they are not in my normal PATH.
Starting from @Anthon's rm list, and applying @bin-s advice to search for newer files, i came up with this bash-script to completely wipe-out my Python-3.6.6 (which had been installed from sources with make altinstall):
prefix='/usr/local/'
pyver='3.6'
rm -rf \
$HOME/.local/lib/Python${pyver} \
${prefix}bin/python${pyver} \
${prefix}bin/python${pyver}-config \
${prefix}bin/pip${pyver} \
${prefix}bin/pydoc \
${prefix}bin/include/python${pyver} \
${prefix}lib/libpython${pyver}.a \
${prefix}lib/python${pyver} \
${prefix}lib/pkgconfig/python-${pyver}.pc \
${prefix}lib/libpython${pyver}m.a \
${prefix}bin/python${pyver}m \
${prefix}bin/2to3-${pyver} \
${prefix}bin/python${pyver}m-config \
${prefix}bin/idle${pyver} \
${prefix}bin/pydoc${pyver} \
${prefix}bin/pyvenv-${pyver} \
${prefix}share/man/man1/python${pyver}.1 \
${prefix}include/python${pyver}m
rm -rI ${prefix}bin/pydoc ## WARN: skip if other pythons in local exist.
Use it with care (e.g. add -I option in rm command, to verify each kill).
in case you still need it.
first of all, it's never advisable to uninstall python. check for instance this link.
having said this, Ubuntu 16.04 does not depend (wasn't build) on Python 3.9 (check this out, for instance). thus, and in principle you shouldn't be having problems fully uninstalling it... as it was my case.
i had no troubles following these steps; which for you/me would be something like:
sudo apt-get clean
sudo apt-get autoremove --purge
sudo apt-get remove python3.9
sudo apt-get autoremove
good luck! Install synaptic using
sudo apt install synapticOpen synaptic

Search for "python 3.9"

Right click on "python 3.9" and Select "mark for complete removal"

Click apply
How can I completely remove and re-install python3.10 that is located in ~/.local ? (Ubuntu 22.04)
How to uninstall python in ubuntu completely and reinstalling it? - Stack Overflow
python - Uninstall python3.8 from Ubuntu 20.04.2 LTS - Stack Overflow
How to uninstall Numpy?
Videos
How I do:
Copy# Remove python2
sudo apt purge -y python2.7-minimal
# You already have Python3 but
# don't care about the version
sudo ln -s /usr/bin/python3 /usr/bin/python
# Same for pip
sudo apt install -y python3-pip
sudo ln -s /usr/bin/pip3 /usr/bin/pip
# Confirm the new version of Python: 3
python --version
caution : It is not recommended to remove the default Python from Ubuntu, it may cause GDM(Graphical Display Manager, that provide graphical login capabilities) failed.
To completely uninstall Python2.x.x and everything depends on it. use this command:
Copysudo apt purge python2.x-minimal
As there are still a lot of packages that depend on Python2.x.x. So you should have a close look at the packages that apt wants to remove before you let it proceed.
Thanks, I hope it will be helpful for you.
On an Ubuntu machine, I have a python 3.10.12 residing in the following directory,
~/.local/lib/python3.10/site-packages
This installation has become corrupted and dist.py cannot interoperate with setuptools anymore. Upgrading setuptools to the latest version breaks compatibilty with my setup.py so that option is not available.
What is the safe way to remove this python3 completely and then re-install it back in-place?
Ubuntu 22.04.1
$ which python
/usr/bin/python3
Warning: This will break Ubuntu 18.04 and 18.10. These instructions apply to the specific situation described in the question, on Ubuntu 16.04.
Warning: I have tested this solution, but not very thoroughly. Make a backup, and proceed with caution.
Remove the repo:
sudo add-apt-repository --remove ppa:fkrull/deadsnakesRefresh apt cache:
sudo apt-get updateRemove the package:
sudo apt-get remove --purge python3.6
I followed the instructions above (1:Remove the repo 2:Refresh apt cache 3:Remove the package and found that a lot of my Linux tools and APPS "Disappeared". Not being an expert in identifying and reinstalling each on demand I opted for a full re-install and update. The advise is to make periodic image and backups more like restore points so that you don't have to start from scratch. Make note of your customizations if you are not already documenting the changes to your machine.
Don't uninstall python3 in ubuntu as it is depended on many python packages if you delete that terminal, firefox browser,idle , will also delete and at last it will show you authentication error
You can uninstall it after installing a python3* version as alternative. You have to install python3.9 available from Ubuntu repository.
sudo apt install python3.9
Here is how to set it as default before uninstalling python3.8.
Without a python3 installed the system will be unusable.
Python3 by default