Install Python 3.12 on Ubuntu 22.04|20.04|18.04

For this tutorial, we will install Python 3.12 from the deadsnakes PPA.

sudo apt update && sudo apt upgrade -y
sudo apt install -y software-properties-common build-essential libffi-dev libssl-dev zlib1g-dev libncurses5-dev libncursesw5-dev libreadline-dev libsqlite3-dev libgdbm-dev libdb5.3-dev libbz2-dev libexpat1-dev liblzma-dev libffi-dev libssl-dev
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install -y python3.12 python3.12-dev python3.12-venv

# To check if the install is successful
python3.12 --version

If you get this error ImportError: cannot import name 'html5lib' from 'pip._vendor' (/usr/lib/python3/dist-packages/pip/_vendor/init.py) , that means you need to re-install pip that matched the new python

curl -sS https://bootstrap.pypa.io/get-pip.py | python3.11

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *