How to re-install Python 3 on Ubuntu

How to re-install Python 3 on Ubuntu

·

2 min read

Python can be tricky to work with, especially when avoiding conflicts. You may need to remove all of the Python versions and re-install it.

Let's see how to do it!

I keep these installation tutorials simple and straightforward because I know how frustrating it is to read through an entire article when you are simply looking for terminal commands. So if this article looks bland, it is very much on purpose :)

Uninstall Python3

Uninstall and re-install Python 3 on Ubuntu 20.04 lts.

List all python versions in default locations

ls /usr/bin/python*

Remove just the python3 package

sudo apt-get remove python3.5

Remove it's dependent packages

sudo apt-get remove --auto-remove python3.5

Remove the configuration and/or data files of python3

sudo apt-get purge python3.5

Remove both configuration and/or data files of python3.5 and it's dependencies

sudo apt-get purge --auto-remove python3.5

Install a new version of python

sudo apt-get update
sudo apt-get install python3

Verify the installation.

python3

You should see something like the following.

Python 3.10.6 (main, Aug 10 2022, 11:40:04) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

ModuleNotFoundError: No module named '_sqlite3'.

sudo apt-get install libsqlite3-dev
./configure --enable-loadable-sqlite-extensions && make && sudo make install

Did you find this article valuable?

Support Davide by becoming a sponsor. Any amount is appreciated!