Uninstall Python Compiled from source
It happens that you no longer need the Python 3.6.5 we installed by using make from the source as described above due to its packages conflicts with other installed version of Python, causing trouble or for whatever reason. The way this version was installed makes it difficult to uninstall by
sudo apt-get remove pythonx,
sudo apt-get purge pythonx,
sudo apt autoremove python or
sudo apt-get remove --purge pythonx or
sudo apt purge pythonx-minimal method because the method has no idea that this version of Python exists. Here, Python 3.6.5 is compiled from source and thus it's not registered with the aptitude package.
In most cases,
make uninstall or
sudo make uninstall may fail to remove the installed Python 3.6.5.
You can also try to get a look at the steps used to install the software by running:
make -n install
If this method fails (because the python developers have not built for make uninstall), the easiest way to uninstall (most makefiles don't have an uninstall target) is to run make install again in our Python 3.6.5 source directory and capture what it sticks where and then remove them. The summary of this approach is as follows:
- Install checkinstall
- Use checkinstall to make a deb of your Python installation
- Use dpkg -r to remove the deb.
checkinstall monitors installation scripts such as "make install" and creates a deb package instead of directly installing the files.
So, we can use checkinstall to create the deb package, and then use the deb package to uninstall the python in /usr/local.
Install the checkinstall package and move to the Python 3.6.5 directory:
Code: Select all
sudo apt-get install checkinstall
cd /home/user/Python-3.6.5
Make the deb package:
Code: Select all
sudo checkinstall -D --fstrans=no make install #This step can be lengthy
Please answer (choosing default answers should be fine) the questions asked by checkinstall. After answering the last question, the process will hang on for sometime and the continue,
Copying files to the temporary directory...
OK
Stripping ELF binaries and libraries...OK
Compressing man pages...OK
Building file list...OK
Building Debian package...
Installing Debian package...OK
Erasing temporary files...OK
Writing backup package...OK
OK
Deleting temp dir...OK
**********************************************************************
Done. The new package has been installed and saved to
/home/user/Python-3.6.5/python_3.6.5-1_amd64.deb
You can remove it from your system anytime using:
dpkg -r python
**********************************************************************
You should end up with a deb package called python_3.6.5-1_amd64.deb and backup-051820182104-pre-python.tgz.
Now, let's uninstall python from source:
Code: Select all
sudo dpkg -i Python-3.6.5.deb # Reinstall python to /usr/local
Check the version of python3.6 installed
Code: Select all
$readlink -f $(which python3.6) | xargs -I % sh -c 'echo -n "%: "; % -V'
$which -a python3.6 #For less info
and then remove it
Code: Select all
sudo dpkg -r Python-3.6.5 # Remove python from /usr/local
See more about
Installing software from source code with checkinstall
If you assume that a Python binary is always named python<something> (python*) and be a binary file, you can just search the entire system for files that match this criterion:
$sudo find / -type f -executable -iname 'python*' -exec file -i '{}' \; | awk -F: '/x-executable; charset=binary/ {print $1}' | xargs readlink -f | sort -u | xargs -I % sh -c 'echo -n "%: "; % -V'
/home/tssfl/Environments/Django_Pro/bin/python3.4: Python 3.4.3
/home/tssfl/flask-pycon2015/venv/bin/python: Python 2.7.6
/home/tssfl/flasky/venv/bin/python: Python 2.7.6
/home/tssfl/Python-3.3.7/python: Python 3.3.7
/home/tssfl/Python-3.6.5/python: Python 3.6.5
/home/tssfl/venv/bin/python: Python 2.7.6
/home/tssfl/yowsup/bin/python: Python 2.7.6
/usr/bin/python2.7: Python 2.7.6
/usr/bin/python3.4: Python 3.4.3
/usr/bin/python3.4m: Python 3.4.3
/usr/local/bin/python3.3: Python 3.3.7
/usr/local/bin/python3.3m: Python 3.3.7
/usr/local/bin/python3.6: Python 3.6.5
/usr/local/bin/python3.6m: Python 3.6.5
See
the difference between pythonx and pythonxm.
The cheaper way to remove the versions of Python you don't want would be to sudo rm -rf /usr/local/bin/python3 and probably remove anything else in /usr/local/bin/py* including symlinks to various parts of the suite.
If your shell remembers removed versions of python,
Code: Select all
$sudo apt-get install --reinstall pythonx
or
will clean them up.