How to install and configure Python on a VPS

How to install and configure Python on a VPS

14:01, 06.01.2022
Autor: Artur Berezhnoy
2 min.
230

Python is one of the most popular and widely used programming languages. If you are developing specialized software on the server-side, you first need to install Python on your VPS. Here's how to do it using the Ubuntu operating system as an example.

Artur Berezhnoy
Generalist
Was werden Sie in diesem Artikel erfahren?

Installing Python on Ubuntu

First, you should know that the current version of Ubuntu 20.04.3 LTS contains Python 3 packages and libraries by default. The same is true for recent Debian distributions. Thus, the first thing you need to do is to update your system with the apt tool:

sudo apt update
sudo apt -y upgrade

We set -y as a confirmation that all parts are ready to be installed. In some cases, you will need to manually confirm the selection through a dialog box during the installation and upgrade of OS components. And when the upgrade procedure is complete, we check the Python version:

python3 -V

You will see the information in front of you with, among other things, the version of the software we are interested in. Now we can install the pip tool, since it is used to manage Python software packages.

sudo apt install -y python3-pip

Individual language packages are installed with the command:

pip3 install module_name

Instead of "module_name" you can write the name of any module you need, from the free Django framework to NumPy. The different frameworks will make development easier for you and allow you to focus on the essentials, getting rid of the routine. For example, the same library NumPy is very useful for scientific calculations, it supports multidimensional arrays and high-level mathematical functions, so development can be indispensable.

The good thing about Python is that it allows you to install many additional packages and development tools to build a solid bridgehead for your programming environment:

sudo apt install -y build-essential libssl-dev libffi-dev python3-dev

Now all that remains is to set up the virtual environment correctly. Python is one of the easiest and most convenient programming languages, which is popular also due to the huge number of available libraries.

how to install and configure python on a vps

Configuring Python on VPS

After installation, we recommend that you set up isolated areas on your VPS so that each of your projects has its own set of dependencies and these projects do not interfere with each other in any way. You can set up the desired number of programming environments for this language with the venv module that comes in the standard library:

sudo apt install -y python3-venv

Next, create a directory with the mkdir command:

mkdir environments
cd environments

Now, to create a development environment, move to the directory and type the command:

python3 -m venv my_env

You can set up new directories with all the items they contain with the pyvenv command, and you can view the list of items with the ls command. Like this:

ls my_env

This way, your projects in the context of the entire server will be isolated from each other and their system and configuration files will not be interchanged. It is also recommended to provide each project with access to the specific packages and frameworks they need to work and develop. Now you know how to install and configure Python on a VPS. Thanks for your attention and see you again!

Verwandte Artikel