Programming plays a huge role in the tech world. Without it, you wouldn’t be able to view this article or use your phone, computer, smart TV etc. In this technology-driven world, learning programming can really give you a competitive edge. This can help innovate and create solutions for the global society.
Programming can be defined as a set of instructions given to a computer to execute. These instructions are written in language that the computer understands. Today there are many programming languages, the most common ones are Java, JavaScript, Ruby, Python, C/C++, Swift e.t.c.
Python is an open-source, high-level object-oriented programming language with a large community. It is one of the most considered languages for beginners. This is mainly because of its simplicity and easy-to-learn syntax. It is used to build a wide range of applications from small and simple scripts to complex machine-learning algorithms. Python is mainly used for:
- Rapid prototyping or production-ready software development.
- Create web applications on servers
- Handling big data and performing complex mathematics.
- Connect to database systems, read and modify files.
- Alongside software to create workflows
The latest release of Python is Python 3.11 made on October 24, 2022. This faster and more user-friendly version has been made available after seventeen months of development. This has resulted in several features and improvements being tagged to it.
The main features associated with Python 3.11 are:
- Faster code execution due to considerable effort in the Faster CPython project
- Better error messages with more informative tracebacks
- Task and exception groups that simplify working with asynchronous code
- Native TOML support for working with configuration files
- Several new typing features that improve Python’s static typing support
- A More powerful Python parser
- Security updates.
Install Python 3.11 on Ubuntu 22.04|20.04|18.04
This guide demonstrates how to install Python 3.11 on Ubuntu 22.04|20.04|18.04 Linux machine.
This guide will provide two methods to get Python 3.11 installed on Ubuntu 22.04|20.04|18.04. The two methods are:
- Installing from the deadsnakes PPA
- Manually build Python 3.11 from the source code
But before we proceed, ensure that the system packages are updated to their latest available versions:
sudo apt update && sudo apt upgrade -y
Now choose one of the method that best works for you.
Method 1 – Install Python 3.11 on Ubuntu from deadsnakes PPA
The deadsnakes PPA provides the simplest method to install Python 3.11 on Ubuntu 22.04|20.04|18.04. It also enables users to receive continued updates, bug fixes, and security updates. A big thumbs up to this custom PPA!
First, install the required dependency packages:
sudo apt install software-properties-common -y
Add the deadsnakes PPA to the APT package manager sources list.
sudo add-apt-repository ppa:deadsnakes/ppa
Proceed as shown:
..........
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
Press [ENTER] to continue or ctrl-c to cancel adding it
Press Enter to continue. Once the PPA has been added, you can install Python 3.11 on Ubuntu using the commands:
sudo apt install python3.11
Verify the installation:
$ python3.11 --version
Python 3.11.4
Method 2 – Install Python 3.11 on Ubuntu from source.
This is an alternative method of installing Python 3.11 on Ubuntu Linux system. With this method, you are guaranteed the latest Python Version. The only problem with this method is that you will not be able to receive continued updates, bug fixes, and security updates through the APT package manager.
Begin by installing the packages required to build Python 3.11 from the source.
sudo apt update && sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev pkg-config -y
Once the packages have been installed, download the latest available Python 3.11 gzipped tarball from the Python official release page.
You can still download the tarball using wget:
wget https://www.python.org/ftp/python/3.11.4/Python-3.11.4.tgz
Extract the downloaded archive:
tar -xf Python-3.11.*.tgz
Now navigate into the directory:
cd Python-3.11.*/
We will check if the required dependencies are met and optimize the binary with the command:
./configure --enable-optimizations
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.11... no
checking for python3.10... no
checking for python3.9... no
checking for python3.8... python3.8
checking Python for regen version... Python 3.8.10
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... "linux"
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
Once checked, start the build process with the command below. We have used -j to provide the number of cores available on the system, this makes the build process faster:
make -j $(nproc)
Sample Output:
........
copying and adjusting /home/ubuntu/Python-3.11.4/Tools/scripts/idle3 -> build/scripts-3.11
copying and adjusting /home/ubuntu/Python-3.11.4/Tools/scripts/2to3 -> build/scripts-3.11
changing mode of build/scripts-3.11/pydoc3 from 664 to 775
changing mode of build/scripts-3.11/idle3 from 664 to 775
changing mode of build/scripts-3.11/2to3 from 664 to 775
renaming build/scripts-3.11/pydoc3 to build/scripts-3.11/pydoc3.11
renaming build/scripts-3.11/idle3 to build/scripts-3.11/idle3.11
renaming build/scripts-3.11/2to3 to build/scripts-3.11/2to3-3.11
gcc -pthread -c -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fno-semantic-interposition -std=c11 -Objects/moduleobject.o Objects/namespaceobject.o Objects/object.o Objects/obmalloc.o Objects/picklebufobject.o Objects/rangeobject.o Objects/setobject.o Objects/sliceobject.o Objects/structseq.o Objects/tupleobject.o Objects/typeobject.o Objects/unicodeobject.o Objects/unicodectype.o Objects/unionobject.o Objects/weakrefobject.o Python/_warnings.o Python/Python-ast.o Python/Python-tokenize.o Python/asdl.o Python/ast.o Python/ast_opt.o Python/ast_unparse.o Python/bltinmodule.o Python/ceval.o Python/codecs.o Python/compile.o Python/context.o Python/dynamic_annotations.o Python/errors.o Python/frame.o Python/frozenmain.o Python/future.o Python/getargs.o Python/getcompiler.o Python/getcopyright.o Python/getplatform.o Modules/timemodule.o Modules/_weakref.o Modules/_abc.o Modules/_functoolsmodule.o Modules/_localemodule.o Modules/_operator.o Modules/_stat.o Modules/symtablemodule.o Modules/pwdmodule.o Modules/xxsubtype.o Python/deepfreeze/deepfreeze.o Modules/getpath.o Python/frozen.o -lpthread -ldl -lutil -lm
make[1]: Leaving directory '/home/ubuntu/Python-3.11.4'
Note: Building Python from source can take a long time, depending on your system. You can adjust the number passed to the -j
option in the make
command to specify the number of parallel build jobs to run, which can speed up the build process.
Once the build process is complete, install Python 3.11 with the command:
sudo make altinstall
We have used altinstall
is used instead of install
to keep the default Python binary path in /usr/bin/python.
Execution output:
.......
Looking in links: /tmp/tmprw_g09fu
Processing /tmp/tmprw_g09fu/setuptools-65.5.0-py3-none-any.whl
Processing /tmp/tmprw_g09fu/pip-22.3.1-py3-none-any.whl
Installing collected packages: setuptools, pip
Successfully installed pip-22.3.1 setuptools-65.5.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
Once complete, check the version:
$ python3.11 --version
Python 3.11.4
Install Python Extensions
Python modules are important since they add functionality to Python. These modules can be installed using the Python Package manager (PIP).
Install PIP on Ubuntu:
curl -sS https://bootstrap.pypa.io/get-pip.py | python3.11
Confirm it’s installed by checking the version:
$ pip3.11 -V
pip 23.0.1 from /usr/local/lib/python3.11/dist-packages/pip (python 3.11)
Now use PIP to install any module. The command to use has the syntax:
sudo pip3.11 install module-name
For example:
sudo pip3.11 install awscli
Sample output:
....
Collecting rsa<4.8,>=3.1.2
Downloading rsa-4.7.2-py3-none-any.whl (34 kB)
Collecting jmespath<2.0.0,>=0.7.1
Downloading jmespath-1.0.1-py3-none-any.whl (20 kB)
Collecting python-dateutil<3.0.0,>=2.1
Downloading python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 247.7/247.7 kB 52.1 MB/s eta 0:00:00
Requirement already satisfied: urllib3<1.27,>=1.25.4 in /usr/lib/python3/dist-packages (from botocore==1.29.78->AWSCLI) (1.26.5)
Requirement already satisfied: pyasn1>=0.1.3 in /usr/lib/python3/dist-packages (from rsa<4.8,>=3.1.2->AWSCLI) (0.4.8)
Requirement already satisfied: six>=1.5 in /usr/lib/python3/dist-packages (from python-dateutil<3.0.0,>=2.1->botocore==1.29.78->AWSCLI) (1.16.0)
Installing collected packages: rsa, python-dateutil, jmespath, docutils, botocore, s3transfer, AWSCLI
Successfully installed AWSCLI-1.27.78 botocore-1.29.78 docutils-0.16 jmespath-1.0.1 python-dateutil-2.8.2 rsa-4.7.2 s3transfer-0.6.0
You can list all the installed modules using the command;
$ pip3.11 list
Package Version
---------------------- ---------------
attrs 21.2.0
Automat 20.2.0
awscli 1.27.78
Babel 2.8.0
bcrypt 3.2.0
blinker 1.4
botocore 1.29.78
certifi 2020.6.20
chardet 4.0.0
click 8.0.3
cloud-init 22.4.2
colorama 0.4.4
command-not-found 0.3
configobj 5.0.6
constantly 15.1.0
cryptography 3.4.8
dbus-python 1.2.18
distro 1.7.0
distro-info 1.1build1
docutils 0.16
httplib2 0.20.2
hyperlink 21.0.0
idna 3.3
importlib-metadata 4.6.4
incremental 21.3.0
......
Verdict
We have successfully gone through how to install Python 3.11 on Ubuntu 22.04|20.04|18.04. You can now use the installed Python 3.11 to build web applications, create workflows, software development etc.
See more:
Install Java 17, Java 11 on Rocky Linux 9 / AlmaLinux 9
Deploy Python 3 Django Application on CentOS 7 with Apache and mod_wsgi
Best Books for Learning Python Programming 2022