Installing Python on Linux Mint

Knowledge of the Python language is one of the most important skills of a system programmer. This programming language is truly indispensable for automating routine tasks. Scripts work in the interpreter mode, they do not need to be compiled, their contents are practically not tied to a specific operating system.

The versatility of this programming language allows you to use it in various areas-from ordinary data parsing to machine learning systems, graphic editors, and even games. In this article, we will talk about how to install Python in Linux Mint.

  • Installing Python 3.9 on Linux Mint
    • 1. Install using Docker
    • 2. Install from repositories
  • Configuring venv
  • Conclusions

Installing Python 3.9 on Linux Mint

Python version 3.8.2 is already pre-installed in Linux Mint 20 Ulyana. The new version should appear in October 2020, but you can already test the beta version 3.9.

1. Install using Docker

Sometimes there is no need to perform a full installation. For example, you just need to check and debug the operation of a single script, or, as in this case, just evaluate the new version of Python. This is very easy to do if Docker is installed. You can download the finished image from the Docker Hub. At the time of writing, an image with the python version:3.9.0rc1 is available:

For example, consider a simple script that displays a message with the text “Hello LOSST readers.” The script will be placed in the /home/mint directory:

vi script.py

print ("Hello LOSST readers")

To execute it, use the following command:

docker run -it --rm --name script-for-python3.9 -v "$PWD":/home/mint -w /home/mint python: 3.9.0rc1 python script.py

As you can see, the script successfully worked with the new version of Python, running with docker.

2. Install from repositories

In order to install Python 3.9 for permanent use, you need to run several commands. Install (if not already installed) software-properties-common:

apt update

sudo apt install software-properties-common

Adding a repository:

sudo add-apt-repository ppa:deadsnakes/ppa

Next, install the Python3.9 package itself:

apt update

sudo apt install python3.9

Python 3.9 installed successfully. Let’s check the version number:

python3.9 -V

Configuring venv

Although Python scripts do not need to be compiled for later use, sometimes they need to be run in a special isolated virtual environment (Virtual Environment). This will help solve problems with different versions of packages. The venv utility serves just that purpose.

Install venv using the command:

sudo apt install python3.9-venv

To create your own virtual environment for working with Python, run the following command:

python3.9 -m venv env-3.9

Here, env-3.9 is an arbitrary name for the Virtual Environment. To activate the desired venv, enter the following command:

source env-3.9/bin/activate

Now let’s run the script we created earlier in this environment:

python3.9 script.py

The script worked successfully.

To deactivate this virtual environment, use the command:

deactivate

Conclusions

Installing Python 3.9 in Linux Mint 20 is no more difficult than installing any other program. The possibilities of this language are huge. For example, it is used in games such as Battlefield 2 and World of Tanks. Instagram and YouTube are written primarily using Python. This language is a good choice for a developer starting out in the world of programming.

Source: losst.ru

(Visited 152 times, 1 visits today)

Leave a Reply

Your email address will not be published. Required fields are marked *