Download your python version from https://www.python.org/downloads/ Open a terminal tar -xzf python3.12.7.tgz
cd Python-3.12.7
Install dependencies sudo apt update sudo apt install build-essential libssl-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python3-openssl git
Run the configuration script ./configure --enable-optimizations --prefix=/usr
make -j $(nproc)
sudo make altinstall
Verify the installation Check that Python 3.12.7 is installed correctly: /usr/bin/python3.12 --version