Python is an open-source high-level programming language with a large community. It is one of the world’s popular programming languages used a key among the top tech companies like google to build all kinds of applications.
The latest stable release version of Python is 3.13 released on October 7, 2024. It comes with innumerable improvements and features such as:
- A brand-new, enhanced interactive interpreter built on top of PyPy that offers colorized exception tracebacks, multi-line editing, and color support.
- An experimental free-threaded build mode that permits threads to operate more concurrently by turning off the Global Interpreter Lock. The Windows and macOS installers also offer the build mode as an experimental feature.
- An experimental, preliminary JIT that lays the foundation for major performance gains.
- Debuggers can now work more reliably because the locals() builtin function (and its C equivalent) has clearly stated semantics when changing the returned mapping.
- Now included is a modified version of mimalloc, which is necessary for the free-threaded build mode and optional but enabled by default if the platform supports it.
- The leading indentation of docstrings has been removed, which lowers memory usage and the size of.pyc files. (The majority of docstring handling utilities already remove the leading indentation.)
- When generating new files, the dbm module’s new dbm.sqlite3 backend is utilized by default.
- MacOS 10.9 was no longer the minimum supported version; instead, it is now 10.13 (High Sierra). In the future, older macOS versions will not be supported.
This guide illustrates two methods of how to install Python 3.13 on Ubuntu 24.04|22.04.
- Install Python 3.13 from the deadsnakes PPA
- Manually build Python 3.13 from the source code.
Option 1- Install Python 3.13 on Ubuntu 24.04|22.04 with APT
Python 3.13 can be downloaded on Ubuntu 24.04|22.04 using a simple APT command. This is a straightforward process and takes the shortest time to complete.
First and foremost, update your APT package index and install the required dependencies.
sudo apt update -y
sudo apt install software-properties-common -y
Then proceed and add the deadsnakes PPA repository to your Ubuntu 24.04|22.04 system as below.
sudo add-apt-repository ppa:deadsnakes/ppa
Press Enter to continue when prompted.
...................
Third-Party Python Modules
==========================
Python modules in the official Ubuntu repositories are packaged to work with the Python interpreters from the official repositories. Accordingly, they generally won't work with the Python interpreters from this PPA. As an exception, pure-Python modules for Python 3 will work, but any compiled extension modules won't.
To install 3rd-party Python modules, you should use the common Python packaging tools. For an introduction into the Python packaging ecosystem and its tools, refer to the Python Packaging User Guide:
https://packaging.python.org/installing/
Sources
=======
The package sources are available at:
https://github.com/deadsnakes/
Nightly Builds
==============
For nightly builds, see ppa:deadsnakes/nightly https://launchpad.net/~deadsnakes/+archive/ubuntu/nightly
More info: https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa
Adding repository.
Press [ENTER] to continue or Ctrl-c to cancel.
Hit:1 http://ke.archive.ubuntu.com/ubuntu noble InRelease
Hit:2 http://ke.archive.ubuntu.com/ubuntu noble-updates InRelease
Hit:3 http://ke.archive.ubuntu.com/ubuntu noble-backports InRelease
Hit:4 http://security.ubuntu.com/ubuntu noble-security InRelease
Get:5 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu noble InRelease [17.8 kB]
Get:6 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu noble/main amd64 Packages [29.1 kB]
Get:7 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu noble/main Translation-en [5408 B]
Fetched 52.4 kB in 2s (24.4 kB/s)
Reading package lists... Done
Now with the deadsnakes repository added, we install Python 3.13 with the single command below.
sudo apt install python3.13
Dependency Tree:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
libpython3.13-stdlib
Suggested packages:
python3.13-venv binutils
The following NEW packages will be installed:
libpython3.13-stdlib python3.13
0 upgraded, 2 newly installed, 0 to remove and 105 not upgraded.
Need to get 5182 kB of archives.
After this operation, 21.5 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Check the installed version.
$ python3.13 --version
Python 3.13.2
Option 2 – Install Python 3.13 on Ubuntu 24.04|22.04 from Source.
With this installation method, you will be guaranteed the latest Python Version although you won’t be able to maintain your package installation through the APT package manager.
Begin by installing the required dependencies to build Python from the source code.
sudo apt update -y
sudo apt install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev
Now proceed and download the latest release version of Python from the official Python downloads page. As of this article, the latest release version was at 3.13.2. You can alternatively obtain the download link and pull the source code with Wget as below.
mkdir tmp && cd tmp
sudo wget https://www.python.org/ftp/python/3.13.2/Python-3.13.2.tgz
With the download complete, extract the Gzipped archive as below.
tar -xf Python-*.tgz
Now navigate into the extracted directory and run the configure
script which performs checks to ensure that all the required dependencies are installed on your system.
cd Python-3.13*/
./configure --enable-optimizations
The --enable optimization
flag is used to optimize the binary by running multiple tests.
Sample Output:
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for Python interpreter freezing... ./_bootstrap_python
checking for python3.13... no
checking for python3.13... no
checking for python3.12... python3.12
checking Python for regen version... Python 3.12.3
checking for pkg-config... no
checking MACHDEP... "linux"
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking for --with-app-store-compliance... not patching for app store compliance
checking for gcc... gcc
.....................
configure: creating ./config.status
config.status: creating Makefile.pre
config.status: creating Misc/python.pc
config.status: creating Misc/python-embed.pc
config.status: creating Misc/python-config.sh
config.status: creating Modules/Setup.bootstrap
config.status: creating Modules/Setup.stdlib
config.status: creating Modules/ld_so_aix
config.status: creating pyconfig.h
configure: creating Modules/Setup.local
configure: creating Makefile
Now initiate the Python 3.13 build process.
make
For faster building, you are required to modify the -j
argument to match the number of cores in your processor. Find the number of processors on your system using thenproc
command.
Sample Output:
Running code to generate profile data (this can take a while):
# First, we need to create a clean build with profile generation
# enabled.
make profile-gen-stamp
make[1]: Entering directory '/home/cloudspinx/tmp/Python-3.13.2'
make clean
make[2]: Entering directory '/home/cloudspinx/tmp/Python-3.13.2'
find . -depth -name '__pycache__' -exec rm -rf {} ';'
find . -name '*.py[co]' -exec rm -f {} ';'
find . -name '*.[oa]' -exec rm -f {} ';'
find . -name '*.s[ol]' -exec rm -f {} ';'
find . -name '*.so.[0-9]*.[0-9]*' -exec rm -f {} ';'
find . -name '*.lto' -exec rm -f {} ';'
find . -name '*.wasm' -exec rm -f {} ';'
find . -name '*.lst' -exec rm -f {} ';'
find build -name 'fficonfig.h' -exec rm -f {} ';' || true
find: ‘build’: No such file or directory
find build -name '*.py' -exec rm -f {} ';' || true
find: ‘build’: No such file or directory
find build -name '*.py[co]' -exec rm -f {} ';' || true
find: ‘build’: No such file or directory
rm -f pybuilddir.txt
rm -f _bootstrap_python
rm -f python.html python*.js python.data python*.symbols python*.map
rm -f ./usr/local/lib/python3.13/os.py
rm -f Programs/_testembed Programs/_freeze_module
rm -rf Python/deepfreeze
rm -f Python/frozen_modules/*.h
rm -f Python/frozen_modules/MANIFEST
rm -f jit_stencils.h
....
With the build process complete, install Python 3.9 on Ubuntu 24.04|22.04 using the make command below.
sudo make altinstall
Here, we are using altinstal
instead of install
because we will overwrite the system’s default Python binary path in /usr/bin/python
.
Sample Output:
Creating directory /usr/local/share/man/man1
/usr/bin/install -c -m 644 ./Misc/python.man \
/usr/local/share/man/man1/python3.13.1
if test "xupgrade" != "xno" ; then \
case upgrade in \
upgrade) ensurepip="--altinstall --upgrade" ;; \
install|*) ensurepip="--altinstall" ;; \
esac; \
./python -E -m ensurepip \
$ensurepip --root=/ ; \
fi
Looking in links: /tmp/tmpt8iwo_8c
Processing /tmp/tmpt8iwo_8c/pip-24.3.1-py3-none-any.whl
Installing collected packages: pip
Successfully installed pip-24.3.1
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager, possibly rendering your system unusable.It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv. Use the --root-user-action option if you know what you are doing and want to suppress this warning.
Now verify your installation.
$ python3.13 --version
Python 3.13.2
Install Modules|Extensions in Python
Modules can be installed using the Python Package manager (PIP). You will simply need the syntax below to get a module installed on your system. You will need to have PIP installed on your system
sudo apt install python3-pip
Then use pip to install a Python module
sudo pip install module-name
Let’s say we want to install the module beautifulsoup4 we will issue the command:
sudo pip install beautifulsoup4
Sample Output:
Collecting beautifulsoup4
Downloading beautifulsoup4-4.13.3-py3-none-any.whl.metadata (3.8 kB)
Collecting soupsieve>1.2 (from beautifulsoup4)
Downloading soupsieve-2.6-py3-none-any.whl.metadata (4.6 kB)
Collecting typing-extensions>=4.0.0 (from beautifulsoup4)
Downloading typing_extensions-4.12.2-py3-none-any.whl.metadata (3.0 kB)
Downloading beautifulsoup4-4.13.3-py3-none-any.whl (186 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 186.0/186.0 kB 642.3 kB/s eta 0:00:00
Downloading soupsieve-2.6-py3-none-any.whl (36 kB)
Downloading typing_extensions-4.12.2-py3-none-any.whl (37 kB)
Installing collected packages: typing-extensions, soupsieve, beautifulsoup4
Successfully installed beautifulsoup4-4.13.3 soupsieve-2.6 typing-extensions-4.12.2
List locally installed Python packages.
$ pip list
Package Version
--------------------- --------------
attrs 23.2.0
Automat 22.10.0
Babel 2.10.3
bcc 0.29.1
bcrypt 3.2.2
beautifulsoup4 4.13.3
blinker 1.7.0
boto3 1.34.46
botocore 1.34.46
certifi 2023.11.17
chardet 5.2.0
click 8.1.6
cloud-init 24.4
colorama 0.4.6
command-not-found 0.3
configobj 5.0.8
constantly 23.10.4
cryptography 41.0.7
dbus-python 1.3.2
distro 1.9.0
distro-info 1.7+build1
httplib2 0.20.4
hyperlink 21.0.0
idna 3.6
incremental 22.10.0
Jinja2 3.1.2
...
Conclusion
That is it! We have come to the end of this guide on how to install Python 3.13 on Ubuntu 24.04|22.04. I have given two alternatives to get Python 3.13 installed on your Ubuntu 24.04|22.04 system. I hope you found it helpful.
See more on this page: