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.

Answer from Anthon on Stack Exchange
Top answer
1 of 5
41

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.

2 of 5
37

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).

Discussions

How can I completely remove and re-install python3.10 that is located in ~/.local ? (Ubuntu 22.04)
Use rye or uv when you reinstall - they make it a pleasure to work with Python. More on reddit.com
🌐 r/learnpython
6
5
October 25, 2024
How to uninstall python in ubuntu completely and reinstalling it? - Stack Overflow
The default python version was 2.7.12 in ubuntu. I installed python2.7.13 using the below commands. Then download using the following command: version=2.7.13 cd ~/Downloads/ wget https://www.pyth... More on stackoverflow.com
🌐 stackoverflow.com
python - Uninstall python3.8 from Ubuntu 20.04.2 LTS - Stack Overflow
This is a pretty dumb question, but is ubuntu dependent on Python 3.8? If it is not, how can I uninstall it from my system? More on stackoverflow.com
🌐 stackoverflow.com
How to uninstall Numpy?
apt remove python3-numpy More on reddit.com
🌐 r/Ubuntu
3
0
July 26, 2020
🌐
Leapcell
leapcell.io › blog › how-to-uninstall-python-a-comprehensive-guide
How to Uninstall Python: A Comprehensive Guide | Leapcell
July 25, 2025 - Check Installed Versions: Type python3 --version to see the current version. ... For Debian-based systems (e.g., Ubuntu): sudo apt-get remove python3.x, replacing x with the specific version number.
🌐
GitHub
gist.github.com › zhensongren › 811dcf2471f663ed3148a272f1faa957
How to uninstall python3 from Ubuntu · GitHub
So try running: sudo apt install --reinstall ubuntu-desktop to solve this problem. It has worked for me (for now haha) but it was also helpful running sudo apt-get install --reinstall pythonVERSION to reinstall everything that is needed.
🌐
Reddit
reddit.com › r/learnpython › how can i completely remove and re-install python3.10 that is located in ~/.local ? (ubuntu 22.04)
r/learnpython on Reddit: How can I completely remove and re-install python3.10 that is located in ~/.local ? (Ubuntu 22.04)
October 25, 2024 -

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

Find elsewhere
🌐
AskPython
askpython.com › home › how to uninstall python 3.7 from ubuntu
How to Uninstall Python 3.7 from Ubuntu - AskPython
April 10, 2025 - Key Point: To prevent breakages, avoid uninstalling Python versions still in use by projects. Now that the installed Python versions are confirmed, we can remove Python 3.7. Since this version was likely installed using the Ubuntu apt package manager, we can use apt to uninstall the Python 3.7 binaries and Debian packages.
🌐
Tech Tips
techtips.easycloudsolutions.com › 2023 › 05 › 04 › how-to-uninstall-python-in-ubuntu-22-04
How to Uninstall Python in Ubuntu 22.04 - Easy Cloud Solutions
December 19, 2025 - Pip is a package manager for Python, which is similar to apt used on a daily basis to download and remove packages from Ubuntu. Using Pip, you can install required packages and Libraries.
🌐
Linux Hint
linuxhint.com › uninstall-python-ubuntu-22-04
Uninstall Python in Ubuntu 22.04 – Linux Hint
Tutorial on the multiple ways of removing Python from Ubuntu 22.04 by uninstalling both CPython and PyPy from the system using APT and from the source code.
🌐
Genius Geeks
geniusgeeks.com › home › how to uninstall python in ubuntu 22.04
How to Uninstall Python in Ubuntu 22.04
December 1, 2023 - This was our take on how to uninstall Python from Ubuntu. We have included everything from uninstalling Pip to both versions of Python.
🌐
Delft Stack
delftstack.com › home › howto › python › python uninstall in ubuntu
How to Uninstall Python in Ubuntu | Delft Stack
March 13, 2025 - This article demonstrates how to delete Python from the Ubuntu Operating System. Learn various methods to uninstall Python, including using terminal commands, purging packages, and cleaning up dependencies. Follow our step-by-step guide to ensure a smooth uninstallation process and verify that Python is completely removed from your system.
🌐
DropVPS
dropvps.com › home › blog › how to uninstall python on ubuntu 25.04
How to uninstall python on ubuntu 25.04 - DropVPS
August 19, 2025 - ⚠️ Warning: Removing the system’s default Python can break core Ubuntu tools like apt. It’s recommended to only remove extra versions you installed manually. That’s it! You have successfully uninstalled Python from Ubuntu 25.04
🌐
Linux Fellas
linuxfellas.com › home › how to install and uninstall python 3 on ubuntu
How To Install And Uninstall Python 3 on Ubuntu - Linux Fellas
January 13, 2025 - If you want to remove the Python 3 on Ubuntu, execute the following apt remove command: ... However, if you want to remove all Python 3 dependencies, use the following apt remove –purge command: ... This way, we’ve learned how to install ...
🌐
YouTube
youtube.com › watch
Completely Uninstall and Remove Python3 From Ubuntu - YouTube
Completely Uninstall and Remove Python3 From UbuntuRemoving python3 from ubuntu can make your computer vulnerable. Because it may also remove other packages ...
Published   January 29, 2023
🌐
YouTube
youtube.com › watch
How to Remove Python from Linux | Remove Python3 on Ubuntu 21.04 | Ubuntu Linux Python - YouTube
How to Remove Python from your Linux | Remove Python3 on Ubuntu 21.04 | Ubuntu Linux PythonDo you want to remove Python3 or Python3-pip from your Ubuntu 21....
Published   May 11, 2021
🌐
Medium
medium.com › @mrngodi › i-uninstalled-python-from-ubuntu-20-04-here-is-how-i-saved-the-day-aaa2348fa885
I uninstalled Python from Ubuntu 20.04! Here is How I saved the day.. | by Mr Ngodi | Medium
December 30, 2024 - If you can’t: Reboot > Choose Advanced Options for Ubuntu -> root · Enter your log in user and password and you should be ready to proceed with steps below. These are the commands the saved my day, in that order. You will need to use sudo if you are not logged in as root · apt-get update apt-get install --reinstall python3 python3-chardet python3-colorama python3-distlib python3-django python3-django-tables2 python3-six python3-html5lib python3-lxml python3-minimal python-pkg-resources python-setuptools python3-urllib3 python3-requests python3-pip python3-virtualenv apt-get install --reinstall python3-dnspython sudo apt-get install --reinstall ubuntu-minimal ubuntu-desktop reboot