Tag Archives: Python

Python 3.14 on Ubuntu 24.04

How to Install Python 3.14 on Ubuntu 24.04

Python is one of the most popular programming languages in the world, widely used for web development, data science, automation, and DevOps. With every new release, Python introduces performance improvements, security patches, and modern syntax features that make development smoother and faster.

This tutorial illustrates two methods of how to install it on your Ubuntu 24.04 OS.

  • Install Python 3.14 from the Deadsnakes PPA
  • Manually build Python 3.14 from the source code

Why Upgrade to Python 3.14?

Before diving into the commands, it’s worth understanding why upgrading to Python 3.14 is beneficial.

Some of the expected improvements in Python 3.14 include:

  • Performance boosts: Faster startup times and optimized memory usage.
  • Enhanced syntax features: Cleaner pattern matching and new language constructs.
  • Improved error messages: More readable and beginner-friendly tracebacks.
  • Security updates: Stronger hashing algorithms and better sandboxing support.

Python 3.14 is fully backward compatible with most 3.x scripts, but testing your projects in a virtual environment is still recommended before full migration.

Update and Upgrade Your System

Start by updating your Ubuntu 24.04 system to avoid package conflicts:

# apt update && sudo apt upgrade -y

Method 1: Install Python 3.14 Using Deadsnakes PPA (Recommended)

This method makes it easy to install Python 3.14 on Ubuntu 24.04 and be able to receive continued updates, bug fixes, and security updates.

The Deadsnakes PPA is a trusted third-party repository that provides newer versions of Python for Ubuntu systems.

First Add the Deadsnakes PPA to the APT package manager sources list:

# add-apt-repository ppa:deadsnakes/ppa -y

Press Enter to continue.

Once the repository has been installed, run an APT update to ensure that the newly imported PPA is reflected.

# apt update

Now you can  install Python 3.14 with the following command:

# apt install python3.14 -y

Then verify the installation with the following command:

# python3.14 --version

You should see output similar to:

Python 3.14.0

If you have installed Python 3.14 using the APT package manager, the PIP will not be installed by default. To install pip3.14, run the following command:

# curl -sS https://bootstrap.pypa.io/get-pip.py | python3.14 

You can check PIP for the Python 3.14 version using the following command:

# pip3.14 -V

pip 25.3 from /usr/local/lib/python3.14/site-packages/pip (python 3.14)

Method 2: Build Python 3.14 from Source

Also, you can compile Python 3.14 manually from the official source code. With this installation method, the main issue is that you cannot quickly update like the APT package manager and will need to recompile for any changes.

First, install the required prerequisite packages for the compilation of the Python 3.10 source code.

# apt install -y build-essential libssl-dev zlib1g-dev \
libncurses5-dev libncursesw5-dev libreadline-dev libsqlite3-dev \
libgdbm-dev libdb5.3-dev libbz2-dev libexpat1-dev liblzma-dev \
tk-dev libffi-dev uuid-dev wget

Now proceed and download the latest release version of Python from the Python official release page.

Alternatively, copy the download link for Python 3.14 gzipped tarball and use wget to pull it with the following command:

# cd /usr/src && wget https://www.python.org/ftp/python/3.14.0/Python-3.14.0.tgz

Once done, extract the archive:

# tar -xf Python-3.14.0.tgz

Now navigate into the extracted directory and run the configure script to check the required dependencies.

# cd Python-3.14.0
# ./configure --enable-optimizations --enable-shared

You can speed up the build process by using all CPU cores:

 make -j 6

Remember, the (-j) corresponds to the number of cores in your system to speed up the build time.

To find out how many cores you have on your system, execute the following code:

# nproc

Output:

6

We have six cores, so in the (make) command, we used (-j 6).

Once the build process has been completed, run the following command to complete the Python installation. Instead of overwriting the system version, we’ll install Python 3.14 as an alternative:

# make altinstall

The altinstall target prevents replacing /usr/bin/python3 and keeps your default Python intact.

Verify your installation:

# python3.14 --version

If everything went smoothly, you’ll see:

Python 3.14.0

Install Python Modules|Extensions

Modules and extensions can be installed using the Python Package manager (PIP).

Use the syntax below to install a Python module of choice.

# pip3.14 install module-name

In this tutorial, We will show you how to install a Python module plotly.

# pip3.14 install plotly

Output:

Collecting plotly
  Downloading plotly-6.4.0-py3-none-any.whl.metadata (8.5 kB)
Collecting narwhals>=1.15.1 (from plotly)
  Downloading narwhals-2.10.2-py3-none-any.whl.metadata (11 kB)
Requirement already satisfied: packaging in /usr/lib/python3/dist-packages (from plotly) (24.0)
Downloading plotly-6.4.0-py3-none-any.whl (9.9 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 9.9/9.9 MB 11.3 MB/s  0:00:00
Downloading narwhals-2.10.2-py3-none-any.whl (419 kB)
Installing collected packages: narwhals, plotly
Successfully installed narwhals-2.10.2 plotly-6.4.0

You can verify your module installation using the following command:

# pip3.14 list | grep plotly
Package                Version             
---------------------- --------------------
..............
plotly 6.4.0
..............

Create a Virtual Environment

After successfully installing Python 3.14, it’s a best practice to create a virtual environment before installing any packages. Virtual environments allow you to isolate dependencies for each project preventing conflicts between system-wide and project-specific Python libraries.

The venv module is not included by default with the Python 3.14 installation, but you can install it manually:

# apt install python3.14-venv -y

This package provides the necessary tools to create and manage virtual environments.

You can create a virtual environment in your project directory. Navigate to your desired location and run:

# python3.14 -m venv myenv

Note: myenv is the name of your virtual environment (you can rename it).

To start using your isolated Python environment, activate it with the following command:

# source myenv/bin/activate

Once activated, your shell prompt should change to show the environment name, similar like this:

(myenv) root@linuxtuto:~#

To deactivate the virtual environment run the following command:

# deactivate

While the environment is active:

    • All installed Python packages will stay local to the project.
    • The global Python installation remains unaffected.

Optional: Set Python 3.14 as Default

Ubuntu 24.04 still ships with Python 3.12 by default. You can switch to Python 3.14 using update-alternatives safely:

# update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1
# update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.14 2
# update-alternatives --config python3

And choose which one to use as Python3 via command:

# update-alternatives --config python3

Select Python 3.14 when prompted, then verify:

# python3 --version

Expected output:

Python 3.14.0

Conclusion

Installing Python 3.14 on Ubuntu 24.04 is simple using the Deadsnakes PPA or by compiling from source. The new release delivers performance improvements, better syntax, and modern features that make development faster and safer.

With Python 3.14 installed, you’re ready to build powerful applications, automate workflows, or explore AI projects with the latest language tools.

For additional help or useful information, we recommend you to check  the official Python documentation.

How to Install Jupyter Notebook on Debian 12

Jupyter Notebook is an open-source web application that allows you to create and share documents that contain live code, equations, visualizations, and narrative text. It’s widely used in various fields such as data science, machine learning, scientific computing, and education.

The term “Jupyter” is derived from the combination of three programming languages: Julia, Python, and R. These were the first languages supported by the Jupyter project, but now it supports many other programming languages through its interactive computing protocol.

In this tutorial, we will show you how to install Jupyter Notebook on Debian 12 OS with Apache web server

Step 1: Update Operating System

Update your Debian 12 operating system to the latest version with the following command:

# apt update && apt upgrade -y

Step 2: Install Pip on Debian 12

Python comes already installed by default on Debian 12. You can verify it by checking its version:

# python3 -V
Output:
Python 3.11.2

If it doesn’t, install Python with the following command:

# apt install python3

Then use the following command to install pip and venv on Debian 12:

# apt install python3-venv python3-pip

Verify your pip installation by checking its version:

# pip3 --version
Output:
pip 23.0.1 from /usr/lib/python3/dist-packages/pip (python 3.11)

Step 3: Install Jupyter Notebook Using Virtualenv

First, create a directory and switch to it with the commands below:

# mkdir /var/www/notebook 
# cd /var/www/notebook

Before you install Jupyter Notebook, you first need to create a Python virtual environment.

# python3 -m venv notebook_env

Next, activate the virtual environment with the following command:

# source notebook_env/bin/activate

Next, install Jupyter Notebook using the following command:

(notebook_env) # pip install jupyter

Once the installation is completed, run the Jupyter Notebook with the following command:

(notebook_env) # jupyter notebook --allow-root

Press the CTRL+C to stop the Jupyter Notebook.

Step 4: Generate Jupyter Notebook Password

First, generate a Jupyter Notebook configuration file with the following command:

(notebook_env) # jupyter notebook --generate-config

You should see the following output:

Writing default config to: /root/.jupyter/jupyter_notebook_config.py

Then run the following command and enter your preferred password:

(notebook_env) # jupyter notebook password

Set a password as shown below:

Enter password: 
Verify password: 
[JupyterPasswordApp] Wrote hashed password to /root/.jupyter/jupyter_server_config.json

This can be used to reset a lost password or if you believe your credentials have been leaked and desire to change your password.

You can prepare a hashed password manually, using the function jupyter_server.auth.passwd():

>>> jupyter_server.auth import passwd
>>> passwd()
Enter password:
Verify password:
'argon2:$argon2id$v=19$m=10240,t=10,p=8$WGqsBZQPacu0FwsczXPlIQ$VXMyCfkJJZETyjdB6aWNSu/t0OrLAVhpkM15wKJYQRU'

Then add the hashed password to your jupyter_notebook_config.py file:

nano /root/.jupyter/jupyter_notebook_config.py
c.ServerApp.password = 'argon2:$argon2id$v=19$m=10240,t=10,p=8$WGqsBZQPacu0FwsczXPlIQ$VXMyCfkJJZETyjdB6aWNSu/t0OrLAVhpkM15wKJYQRU'

Now, deactivate from the Python virtual environment with the following command:

deactivate

Step 5: Create a Systemd service

Next, it is a good idea to create a systemd service file to handle the Jupyter Notebook service. You can create it with the following command:

# nano /lib/systemd/system/jupyter.service

Add the following lines:

[Unit]
Description=Jupyter Notebook

[Service]
Type=simple
PIDFile=/run/jupyter.pid
ExecStart=/var/www/notebook/notebook_env/bin/jupyter-notebook --config=/root/.jupyter/jupyter_notebook_config.py --allow-root
User=root
Group=root
WorkingDirectory=/var/www/notebook/notebook_env
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

Save and close the file and then reload the systemd daemon with the following command:

# systemctl daemon-reload

Then start the jupyter service and activate it at system startup with the following command:

# systemctl start jupyter
# systemctl enable jupyter

Edit the configuration file and enable remote access:

nano /root/.jupyter/jupyter_notebook_config.py

Uncoment and change the following line to True:

c.ServerApp.allow_remote_access = True

To implement the changes, you need to restart the jupyter service:

# systemctl restart jupyter

Step 6: Configure Apache as a Reverse Proxy for Jupyter Notebook

Jupyter Notebook is started and running on port 8888.You can install it via apt package manager by executing the following command.

# apt install apache2

You can verify the status of the Apache service using the systemctl status command:

# systemctl status apache2

Next run the following commands to enable necessary modules:

# /usr/sbin/a2enmod proxy
# /usr/sbin/a2enmod proxy_http

Run the commands below to create a new VirtualHost file called jupyter in the /etc/apache2/sites-available/ directory.

# nano /etc/apache2/sites-available/jupyter.conf

Paste the content as shown below:

 <VirtualHost *:80>
    ServerAdmin admin@your-domain.com
    DocumentRoot /var/www/html/
    
    ServerName your-domain.com
    ServerAlias www.your-domain.com

    ProxyPass / http://127.0.0.1:8888/
    ProxyPassReverse / http://127.0.0.1:8888/> 

    ErrorLog /var/log/apache2/your-domain.com-error_log
    CustomLog /var/log/apache2/your-domain.com-access_log common

 </VirtualHost>

Remember to replace your-domain.com with the domain name of your server.

Then save and exit the configuration file.

To enable this site run the following command:

# ln -s /etc/apache2/sites-available/jupyter.conf /etc/apache2/sites-enabled/jupyter.conf

To implement the changes, you need to restart the Apache webserver:

# systemctl restart apache2

Step 7: Accessing Jupyter Notebook Web Interface

Open your web browser using the URL http://your-domain.com. You should see the Jupyter login page:

Enter your password and click on the Login button. You should see the dashboard on the following screen:

Comments and Conclusion

That’s it. You have successfully installed Jupyter Notebook on Debian 12.

For additional help or useful information, we recommend you to check  the official Jupyter Notebook documentation.

If you have any questions please leave a comment below.

How to Install Odoo 17 on Debian 12

Odoo is an open-source suite of business management software applications that encompasses a wide range of business needs, including customer relationship management (CRM), sales, project management, inventory management, manufacturing, financial management, and more.

It is widely used by businesses of various sizes and across different industries to streamline their operations, improve productivity, and manage their business processes more efficiently. Its flexibility, scalability, and cost-effectiveness make it a popular choice for organizations seeking comprehensive business management solutions.

In this tutorial, we will show you how to install Odoo 17 on Debian 12 OS.

Step 1: Update Operating System

Update your Debian 12 operating system to make sure all existing packages are up to date:

# apt update && apt upgrade

Then install all the required packages for the Odoo 17 setup on the Debian 12 OS.

# apt install python3 python3-dev python3-pip python3-venv python3-setuptools build-essential libzip-dev libxslt1-dev libldap2-dev python3-wheel libsasl2-dev node-less libjpeg-dev xfonts-75dpi xfonts-base libpq-dev libffi-dev fontconfig git wget nodejs npm

Step 2: Install PostgreSQL

Odoo uses PostgreSQL as a database backend, so you will need to install PostgreSQL on your server.

You can run the following command to install the PostgreSQL server:

# apt-get install postgresql-15

After the successful installation, start the PostgreSQL service and enable it to start after the system reboot:

# systemctl start postgresql
# systemctl enable postgresql

Verify that is active and running on your server:

# systemctl status postgresql
Output
● postgresql.service - PostgreSQL RDBMS
     Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; preset: enabled)
     Active: active (exited)
   Main PID: 18666 (code=exited, status=0/SUCCESS)
        CPU: 2ms

Now create an Odoo user in PostgreSQL:

# su - postgres -c "createuser -s odoo" 

This will add a new role odoo in the PostgreSQL server.

Step 3: Install Node.js

To install Node.js and npm on your Debian OS use the following command:

# apt install nodejs npm

Also, install the following module to enable RTL support:

# npm install -g rtlcss

Step 4: Installation of wkhtmltox

To generate PDF reports successfully, wkhtmltopdf is necessary. PDF reports are a crucial component of any organization.

First install the xfonts dependency before installing wkhtmltopdf:

# apt-get install xfonts-75dpi xfonts-base

Now download and install wkhtmltopdf using the following commands:

# wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-3/wkhtmltox_0.12.6.1-3.bookworm_amd64.deb
# dpkg -i wkhtmltox_0.12.6.1-3.bookworm_amd64.deb

Verify if the wkhtmltopdf installation is successful by checking the version:

# wkhtmltopdf --version
wkhtmltopdf 0.12.6.1 (with patched qt)

Step 5: Create an Odoo User

Create a new system user for managing the Odoo processes on the Odoo server.

# adduser --system --group --home=/opt/odoo --shell=/bin/bash odoo

Step 6: Install Odoo

Switch to the user that you have created before to avoid encountering issues related to access rights.

# su - odoo

Now, download the Odoo 17 source code from the git repository and install it:

# git clone https://www.github.com/odoo/odoo --depth 1 --branch 17.0 /opt/odoo/odoo

Next run the following command to generate a new Python virtual environment.

# python3 -m venv odoo-env

Activate the virtual environment with the following command:

# source odoo-env/bin/activate

Then install the required Python packages:

(odoo-env) $ pip3 install wheel
(odoo-env) $ pip3 install -r odoo/requirements.txt

After completing the process of installing all requirements to deactivate the virtual environment run the following command:

(odoo-env) $ deactivate

Execute the following command to create a directory for custom addons:

# mkdir /opt/odoo/custom-addons

Next exit from the Odoo user:

# exit

Create an Odoo log directory and provide it the required write permissions.

# mkdir /var/log/odoo
# chown odoo:odoo /var/log/odoo

Step 7: Create Odoo Configuration File

Create the Odoo configuration file.

# nano /etc/odoo.conf

Then paste the following configuration into it.

[options]
admin_passwd = Strong_admin_Password
db_host = False
db_port = False
db_user = odoo
db_password = False
logfile = /var/log/odoo/odoo-server.log
addons_path = /opt/odoo/odoo/addons,/opt/odoo/custom-addons
xmlrpc_port = 8069

Remember to update the value of the “Strong_admin_Password” key above with a more secure password.

Step 8: Create a Systemd Service File

Create a systemd service file to manage the Odoo service:

# nano /etc/systemd/system/odoo.service

Paste the following content into the odoo.service file:

[Unit]
Description=Odoo
Requires=postgresql.service
After=network.target postgresql.service

[Service]
Type=simple
SyslogIdentifier=odoo
PermissionsStartOnly=true
User=odoo
Group=odoo
ExecStart=/opt/odoo/odoo-env/bin/python3 /opt/odoo/odoo/odoo-bin -c /etc/odoo.conf
StandardOutput=journal+console

[Install]
WantedBy=multi-user.target

Reload system daemon and start the service:

# systemctl daemon-reload
# systemctl start odoo
# systemctl enable odoo

To confirm everything is working normally, check the status of service:

# systemctl status odoo

Output:

● odoo.service - Odoo
     Loaded: loaded (/etc/systemd/system/odoo.service; enabled; preset: enabled)
     Active: active (running)
   Main PID: 2270 (python3)
      Tasks: 4 (limit: 2273)
     Memory: 110.0M
        CPU: 1.622s
     CGroup: /system.slice/odoo.service
             └─2270 /opt/odoo/odoo-env/bin/python3 /opt/odoo/odoo/odoo-bin -c /etc/odoo.conf

Step 9: Access Odoo server

Open your web browser and type http://your-IP-address:8069 and you will see the following screen:

Fill the required information and then click the “Create Database” button to complete the installation.

After successfully creating the Odoo database, you will be redirected to the login page.

Enter your login credentials and you will be redirected to apps page:

Comments and Conclusion

That’s it. You have successfully installed Odoo 17 on Debian 12. For additional information, you can check the official Odoo 17 documentation.

If you have any questions please leave a comment below.

How to Install Python 3.12 on Ubuntu 22.04

Python is a high-level, interpreted programming language known for its simplicity, readability, and versatility. It is used for a wide range of applications, including web development, data analysis, artificial intelligence, scientific computing, automation, and more.

Python’s versatility and ease of use make it an ideal choice for both beginners and experienced developers. It is often recommended as a first programming language due to its simplicity and readability.

Python 3.12 is the latest stable release of the Python programming language. This tutorial illustrates two methods of how to install it on your Ubuntu 22.04 OS.

  • Install Python 3.12 from the deadsnakes PPA
  • Manually build Python 3.12 from the source code

Update Operating System

Update your Ubuntu 22.04 operating system to the latest version with the following command:

# apt update && apt upgrade -y

Method 1: Install Python 3.12 with APT

Installing Python 3.12 on Ubuntu 22.04 using APT is quite easy, a big thumbs up to the deadsnakes custom PPA!

This makes it easy to install Python on Ubuntu and be able to receive continued updates, bug fixes, and security updates.

Install the prerequisite for adding custom PPAs:

# apt install software-properties-common -y

Then proceed and add the deadsnakes PPA to the APT package manager sources list:

# add-apt-repository ppa:deadsnakes/ppa

Press Enter to continue.

Once the repository has been installed, run an APT update to ensure that the newly imported PPA is reflected.

# apt update

You can now install Python 3.12 with the following command:

# apt install python3.12

To verify the installation and Python 3.12 build version, perform the following:

# python3.12 --version
3.12.0

If you have installed Python 3.12 using the APT package manager, the PIP will not be installed by default. To install PIP, run the following command:

# curl -sS https://bootstrap.pypa.io/get-pip.py | python3.12 

You can check PIP for the Python 3.12 version using the following command:

# pip3.12 -V

pip 23.2.1 from /usr/local/lib/python3.12/site-packages/pip (python 3.12)

Method 2: Install Python 3.12 from Source

The other alternative to get Python 3.12 installed on your Ubuntu 22.04 OS is by building it from the source code.

With this installation method, the main issue is that you cannot quickly update like the APT package manager and will need to recompile for any changes.

First, install the required prerequisite packages for the compilation of the Python 3.12 source code.

# apt install 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 Python official release page.

Alternatively, copy the download link for Python 3.12 gzipped tarball and use wget to pull it with the following command:

# wget https://www.python.org/ftp/python/3.12.0/Python-3.12.0.tgz

Once done, extract the archive:

# tar -xf Python-3.12.0.tgz

Now navigate into the extracted directory and run the configure script to check the required dependencies. The –-enable optimization flag optimizes the binary by running multiple tests.

# cd Python-3.12.*/
# ./configure --enable-optimizations

Now initiate the Python 3.12 build process:

# make -j 4

Remember, the (-j) corresponds to the number of cores in your system to speed up the build time.

To find out how many cores you have on your system, execute the following code:

# nproc

Output:

4

We have four cores, so in the (make) command, we used (-j 4).

Once the build process has been completed, run the following command to complete the Python installation on the Ubuntu 22.04 system.

The altinstall prevents the compiler to override default Python versions.

# make altinstall

Verify your installation:

# python3.12 --version
Python 3.12.0

Install Python Modules|Extensions on Ubuntu 22.04

Modules and extensions can be installed on Ubuntu 22.04 using the Python Package manager (PIP).

Use the syntax below to install a Python module of choice.

# pip3.12 install module-name

In this tutorial, We will show you how to install a Python module numpy.

# pip3.12 install numpy

Output:

Collecting numpy
  Obtaining dependency information for numpy from https://files.pythonhosted.org/packages/e3/e2/4ecfbc4a2e3f9d227b008c92a5d1f0370190a639b24fec3b226841eaaf19/numpy-1.26.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata
  Downloading numpy-1.26.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (58 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 58.5/58.5 kB 687.4 kB/s eta 0:00:00
Downloading numpy-1.26.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.9 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 17.9/17.9 MB 1.2 MB/s eta 0:00:00
Installing collected packages: numpy
Successfully installed numpy-1.26.0

You can verify your module installation using the following command:

# pip3.12 list
Package                Version             
---------------------- --------------------
..............
numpy 1.26.0
..............

Use Python 3.12 as default Python3

First, check the current default version using the below command from the terminal.

python3 --version

Output:

Python 3.10.12

Use update-alternatives to create symbolic links to Python3:

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.12 2

And choose which one to use as Python3 via command:

sudo update-alternatives --config python3
 Selection    Path                        Priority   Status
------------------------------------------------------------
* 0           /usr/local/bin/python3.12     2        auto mode
  1           /usr/bin/python3.10           1        manual mode
  2           /usr/local/bin/python3.12     2        manual mode

Press <enter> to keep the current choice[*].

Now check the default version using the below command:

# python3 --version

Output:

Python 3.12.0

That is it!  You are now set to use Python 3.12 to build web applications, software development, create workflows e.t.c

Comments and Conclusion

In the tutorial, you have learned how to install Python 3.12 on Ubuntu 22.04 using APT or install it using source code.

For additional help or useful information, we recommend you to check  the official Python documentation.

If you have any questions please leave a comment below.

How To Install Python 3.10 on Ubuntu 20.04

Python is an open-source high-level programming language with a large community. It is often used for machine learning, deep learning, computer vision, and data analysis.

The latest stable release version of Python is 3.10.1 released on December 6, 2021, and it contains many new features and optimizations.

This tutorial illustrates two methods of how to install Python 3.10 on the Ubuntu 20.04 system.

  • Install Python 3.10 from the deadsnakes PPA
  • Manually build Python 3.10 from the source code

Update Operating System

Update your Ubuntu 20.04 operating system to make sure all existing packages are up to date:

$ sudo apt update && sudo apt upgrade -y

Method 1: Install Python 3.10 with APT

Installing Python 3.10 on Ubuntu 20.04 using APT is quite easy, a big thumbs up to the deadsnakes custom PPA! This makes it easy to install Python on Ubuntu and be able to receive continued updates, bug fixes, and security updates.

Install the prerequisite for adding custom PPAs:

$ sudo apt install software-properties-common -y

Then proceed and add the deadsnakes PPA to the APT package manager sources list:

$ sudo add-apt-repository ppa:deadsnakes/ppa

Install Python 3.10 on Ubuntu 20.04

Press Enter to continue.

Once the repository has been installed, you can now install Python 3.10 with the following command:

$ sudo apt install python3.10

To verify the installation and Python 3.10 build version, perform the following:

$ python3.10 --version
3.10.1

Method 2: Install Python 3.10 from Source

The other alternative to get Python 3.10 installed on your Ubuntu 20.04 system is by building it from the source code. With this installation method, the main issue is that you cannot quickly update like the APT package manager and will need to recompile for any changes.

First, install the required prerequisite packages for the compilation of the Python 3.10 source code.

$ sudo apt install 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 Python official release page.

Alternatively, copy the download link for Python 3.10 gzipped tarball and use Wget to pull it with the following command:

$ sudo wget https://www.python.org/ftp/python/3.10.1/Python-3.10.1.tgz

Once done, extract the archive:

$ sudo tar -xf Python-3.10.*.tgz

Now navigate into the extracted directory and run the configure script to check the required dependencies. The –-enable optimization flag optimizes the binary by running multiple tests.

cd Python-3.10.*/
./configure --enable-optimizations

Now initiate the Python 3.10 build process:

make -j 4

Remember, the (-j) corresponds to the number of cores in your system to speed up the build time.

To find out how many cores you have on your system, execute the following code:

$ nproc

Output:

4

We have four cores, so in the (make) command, we used (-j 4).

Once the build process has been completed, run the following command to complete the Python installation on the Ubuntu 20.04 system.

The altinstall prevents the compiler to override default Python versions.

$ sudo make altinstall

Verify your installation:

$ python3.10 --version
Python 3.10.1

Install Python Modules|Extensions on Ubuntu 20.04.

Modules and extensions can be installed on Ubuntu 20.04 using the Python Package manager (PIP).

You can check PIP for the Python 3.10 version using the following command:

$ pip3.10 -V

pip 21.2.4 from /usr/local/lib/python3.10/site-packages/pip (python 3.10)

Then use the syntax below to install a Python module of choice.

$ sudo pip3.10 install module-name

In this tutorial, We will show you how to install a Python module babel.

$ sudo pip3.10 install babel

Output:

Collecting babel
Downloading Babel-2.9.1-py2.py3-none-any.whl (8.8 MB)
|████████████████████████████████| 8.8 MB 5.2 kB/s
Collecting pytz>=2015.7
Downloading pytz-2021.3-py2.py3-none-any.whl (503 kB)
|████████████████████████████████| 503 kB 6.0 MB/s
Installing collected packages: pytz, babel
Successfully installed babel-2.9.1 pytz-2021.3

You can verify your module installation using the following command:

$ pip3.10 list
Package                Version             
---------------------- --------------------
..............
Babel 2.9.1
..............

Use Python 3.10 as default Python3

First, check the current default version using the below command from the terminal.

python3 --version

Output:

Python 3.8.10

Use update-alternatives to create symbolic links to python3

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.10 2

And choose which one to use as Python3 via command:

sudo update-alternatives --config python3
 Selection    Path                        Priority   Status
------------------------------------------------------------
* 0           /usr/local/bin/python3.10     2        auto mode
  1           /usr/bin/python3.8            1        manual mode
  2           /usr/local/bin/python3.10     2        manual mode

Press <enter> to keep the current choice[*].

Now check the default version using the below command:

python3 --version

Output:

Python 3.10.1

That is it!  You are now set to use Python to build web applications, software development, create workflows e.t.c

Comments and Conclusion

In the tutorial, you have learned how to install Python 3.10 on Ubuntu 20.04 using APT or install it using source code.