Prep - Linux (mainly for new servers)
You may need a C compiler if you haven’t yet downloaded:
sudo apt update && sudo apt install build-essential
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev pkg-config make -y
sudo apt install libpq-dev
Note: pkg-list and zlib1g-dev seemed necessary to build, the others for modules like lzma, _ctypes (for pandas) etc
sudo apt install pkg-list zlib1g-dev uuid-dev lzma-dev liblzma-dev libffi-dev
Installation - Linux
Download the latest version:
Choose Gzipped Tarball https://www.python.org/downloads/release/python-3120/
tar -xvf UNZIPPEDPYTHONFILE
you will now have a directory like Python3.12.xxxsudo mv Python3.12.0 /opt/
Move python installation directory to /opt/ to keep home cleancd ~/opt/Python3.12.0
into the directory and run each command./configure --enable-optimizations
make
Builds Python, this step takes some time.sudo make altinstall
altinstall skips creating the python link and the manual pages links, install will hide the system binaries and manual pages. This means that we will leave the system python installation untouched
Python is now installed.
Last important step is to configure the system links:
sudo ldconfig /opt/Python3.12.0
Finally you can test:
python3.12
Or make a 3.12 virtual env:
python3.12 -m venv ~/venv/my-new-env
or local for a VS Code:
python3.12 -m venv .virtualenv
Be careful which commands use sudo as running the ./configure or first make as sudo will cause Python to have files which require elevated permissions.