-
Install pre-requisites
sudo apt install build-essential libssl-dev libffi-dev software-properties-common libbz2-dev libncurses-dev libncursesw5-dev libgdbm-dev liblzma-dev libsqlite3-dev tk-dev libgdbm-compat-dev libreadline-dev
-
Download the python version you want from https://www.python.org/downloads/source/
cd /opt sudo wget https://www.python.org/ftp/python/3.9.16/Python-3.9.16.tar.xz
-
Extract the downloaded source
sudo tar -xvf Python-3.9.16.tar.xz
-
Read the info
cd Python-3.9.16/ cat README.rst
-
Compile and Install python
./configure make
-
When running
make
you may get a message similar to the below:
Python build finished successfully!
The necessary bits to build these optional modules were not found:
_bz2 _curses _curses_panel
_dbm _gdbm _lzma
_sqlite3 _tkinter _uuid
readline zlib
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
Ideally these modules are installed with apt
:
sudo apt libbz2-dev libncurses-dev libncursesw5-dev libgdbm-dev liblzma-dev libsqlite3-dev tk-dev libgdbm-compat-dev libreadline-dev
-
Install python into the path:
make test # optional sudo make install
-
This installs the python binary to
/usr/local/bin/python3