1. Go to the Python Download page. https://www.python.org/downloads/release/python-3130/
Download the Gzipped source tarball.
2. Extract the tgz file into a folder
tar -xvf Python-3.13.0.tgz
3. Before start installing the Python, install the system-level dependencies and packages
sudo apt update sudo apt install -y build-essential libffi-dev libsqlite3-dev zlib1g-dev \ libreadline-dev libbz2-dev liblzma-dev libncursesw5-dev libgdbm-dev \ libssl-dev libdb-dev uuid-dev tk-dev
4. Now install the Python. Go to the extracted directory Python-3.13.0 and run these commands in order. This will take some time.
./configure --enable-optimizations --with-system-ffi --with-computed-gotos \ --enable-loadable-sqlite-extensions --enable-shared --prefix=/usr/local
without --enable-loadable-sqlite-extensions option you might get the below error while using code related to panda/MySQL/SQLite.
ModuleNotFoundError: No module named '_sqlite3'
Continue with below commands
make
make test
sudo make install
5. Now verify the installation by invoking the python3 or python3.13 interpreter.
6. If you get the below error
./python3: error while loading shared libraries: libpython3.13.so.1.0: cannot open shared object file: No such file or directory
It means the system cannot locate the shared library (libpython3.13.so.1.0). This happens because we enabled shared libraries with --enable-shared during configure, but the system’s dynamic linker doesn't know where to find them.
Fix this error by running the below command
echo "/usr/local/lib" | sudo tee -a /etc/ld.so.conf.d/python3.13.conf
sudo ldconfig
Explanation:
Temporary Fix (Session Only)
If you need a quick fix without modifying system files, export the library path manually:
Note: This change is temporary and will reset when you close the terminal. Add it to your ~/.bashrc or ~/.profile if you want it to persist.
7. Create a virtual environment
virtualenv -p /usr/local/bin/python3.13 venv-name
activate it and install the dependencies.