Traceroute – network tracing in Linux
Introduction
Python is an interpreted programming language. The author is Guido van Rossum, a developer from Holland. Python is a feature-rich language, and beginners quickly get used to the syntax of the language and program in a convenient text editor or use an integrated development environment. Using the Python language, you can get information about errors in the written code. With this guide, you will be able to install the latest version of Python on Ubuntu Server 22.04.
Preparing for installation
Before installing the packages, you need to follow our guide to running Ubuntu Server 22.04 as a standard user.
Download Python 3
Let’s update the package index and run the command to update the packages to the latest releases:
sudo apt update && sudo apt upgrade -y
Checking the Python version goes like this:
python3 --version
#Output
Python 3.10.6
sudo apt install python3-pip -y
pip3 install matplotlib

To make sure the software environment is reliable, you need to install several packages
sudo apt install build-essential libssl-dev libffi-dev python3-dev
Setting up a virtual environment
A virtual development environment on a production server is considered a great solution compared to running in a main development environment. In a virtual environment, you can edit and not damage the files of the main development environment. We can create as many virtual environments as we need. Each virtual environment is deployed in different directories on our server. The directories contain files for initializing the virtual environment.
The virtual environment is deployed using the installed venv (virtual environment) package:
sudo apt install python3-venv -y
mkdir test
cd test
python3 -m venv test_env

The generated files configure the virtual environment to work separately from our host files. Activation of the environment is as follows, and to disable the environment, you must run the deactivate command:
source test/test_env/bin/activate
deactivate

In the figure, you can see that after launch, an inscription appears in front of the user name (test_env) indicating that all commands are executed in a virtual environment, the next step is to consider running a regular code written in the Python programming language.
Testing the virtual environment
After activation, you need to create a file with the extension .py:
vim thanks.py
print("Dear User,\n"
"Thank you for using tutorials from \n"
"Serverspace Team")
python3 thanks.py

At this point, the stage ends and in order to complete the process of working in the virtual environment, we will execute the “deactivate” command and return to the normal environment.
Conclusions
In this instruction:
- Considered options for updating software packages and updating the package index;
- Installed the Python programming language libraries using the pip3 package management system;
- Considered the activation and deactivation of the virtual environment;
- Tested work in a virtual environment.