Using Python on Linux is one easy and fun way to get started in programming. What tribute to Guido Van Rossum, the creator of this popular programming language, let's see how to configure a Python programming environment on our Linux distribution.
Table of Contents
Why use Python on Linux?
Python is an easy-to-learn programming language. It has a huge base of documentation in our language (much of it free) and can be used both for creating small terminal applications or large projects with a graphical interface.
The code developed in Python can be used on Linux, Windows, Mac, Android and on different types of devices like smart TVs and GPS.
Starting to use Python
Since most (if not all) Linux distributions They come prepared to use Python, the first thing is to check the version that we have installed. At this time, branch 2 and branch 3 coexist. However, branch 2 will disappear in 2020.
We can check the version we are using with the command
If you are using a relatively new distribution, you may get an error message. If so try this:
If you used the first command and the version number starts with 2, try the second command to see if you have Python 3 installed.
If you don't have a version, look for Python in your distribution's software manager to install it.
As well it is recommended to install Pip.Pip is the acronym for Pip Installs Packages, a package manager that will make it easier for you to get libraries for Python.
In Debian and derivatives you can do it with the command
sudo apt install python3-pip
In other distributions it simply looks for python3-pip in the package manager
Let's test the code.
In the terminal type:
Let's do some math
Note that since it does not have quotes, what is printed is the result. Instead, if we do:
We will see what we put in parentheses.
We can use variables.
Type in the terminal.
It is also possible to do this with words. We just have to add quotes.
print("El mejor blog sobre Linux es ", blog)
Now let's work with data entered by us.
In the terminal we write:
numero1=input("Ingrese un número: ")
Pressing Enter will ask us to enter a number. After doing it and pressing Enter, we type:
numero2=input("Ingrese otro número: )
We press Enter, we write the other number and we press Enter again.
print (number1 + number2)
Writing longer programs
You may have noticed that using the terminal it is impossible to write long programs. In fact, there are several integrated development environments that make it easy to write Python code. Isaac commented some of them in this article. However, for the purposes of this article we are going to settle for the text editor.
If you still have the terminal open, close it. Now open the text editor of your distribution and write.
nombre=input("¿Cuál es tu nombre: ?")
print(nombre, "cree que", blog, "es el mejor blog sobre Linux")
Save it in your personal folder with the name test.py.
Open terminal and type
As I said above, there are many integrated development environment options that you can use to create code in Linux. In my opinion, the best alternative is VSCodium.
VSCodium is built on the source code of Visual Studio Code, MIcrosoft's integrated development environment. The difference is that it compiles without any of the tracking tools that the company adds to it. The program can be used on Windows, Linux and Mac and downloaded from here:
Once installed, from the extensions menu, install the extension Python.