Python is a programming language that was developed with one goal in mind: It should make it easy for everyone, regardless of their knowledge and experience in computer science. This innovative code system, developed by Guido van Rossum over 30 years ago and still evolving today under his watchful eye (but never too much), allows users to access the tools they need without any prior knowledge of how things work under the surface – and that makes success possible at every turn!
The basic idea behind Python is that code readability is more important than anything else.
Because of this philosophy, Python has many features that set it apart from other programming languages. For example, Python offers extensive support for object-oriented programming (OOP) and is easy to learn even for beginners. Python also has a large standard library that provides a variety of modules for performing tasks, which is supported by the language’s strong integration with C.
The language itself consists of a large standard library made up of modules (roughly equivalent to libraries in other languages) and an extensive core library. Many of these are available as packages that can be installed using the system package manager or the Python Package Manager.
Python interpreters are available for a range of operating systems, which means you can write and run Python code on any platform.
And another amazing thing about this programming language is that it can work with server-side scripts (with the aim of increasing efficiency) as well as individual end users who may want something customised just for them!
Python uses the syntax of the then popular C language to make the code understandable to programmers of other languages. Bill Joy therefore described Python as “a great language for teaching because it is so much fun”.
Lisp-style programming is supported by Python’s design. It has filter(), map() and reduce() functions, list comprehensions, dictionaries and sets, generators, coroutines, strings and Unicode as native data types, exception handling with a type hierarchy, and garbage collection. A large number of extensions have been written to complement the standard library. Various system calls and libraries are supported, as well as a large number of bindings.
The name Python comes from the British comedy group Monty Python, whose Flying Circus was broadcast in the early 1970s. The group’s title was a pun on the name of the BBC program Doctor Who, which Monty Python member Terry Jones had worked on.
In this guide, we’ll show you how to install Python on Almalinux 8, how to get started with the language, and how to learn some basic programming concepts by creating a simple Python program. Let’s go!
In order to install Python on Almalinux 8, you’ll need to be logged in as root. You’ll also need an Internet connection, since the installation process will download the necessary files from Python’s official website.
Python can be installed on Almalinux 8 using either the default repositories or the Python official software source. This guide will show you how to install it from both sources.
Installing Python on AlmaLinux Using DNF
The DNF package management tool is the default package manager on Almalinux 8. DNF stands for “Dandified Yum”, and is a fork of the older Yum package manager.
This is the easiest way to install Python 3 on Almalinux 8. But you might not the latest version of Python 3. The default repositories on Almalinux 8 are not always up-to-date.
First, run the command below to make sure your system is up-to-date.
sudo dnf update -y
Next, run the command below to install Python 3.9 with DNF. python39 is the specific version of Python you wish to install (in this case, 3.9).
sudo dnf install python39 -y
Once the installation is complete, run the command below to ensure Python 3 has been installed.
The output should look like this:
Installing Python Using Source Code
If you want to install the latest version of Python 3, you must download it from Python’s official website and install it yourself. This section will show you how to install Python 3.90 from source code. You can replace 3.9 with any newer version of Python 3 you wish to install.
Due to its nature, Python source code is constantly being developed and updated.
There are two branches: main and legacy. The main branch is the official Python branch, which is typically the most up-to-date language version. The legacy branch is an older version that will not be receiving any future updates. Since we’re learning to install Python 3, we will use the main branch.
First, run the command below to install the required dependencies.
sudo dnf groupinstall "Development Tools" -y sudo dnf install bzip2-devel libffi-devel openssl-devel -y
groupinstall installs the required development tools named Development Tools, a collection of packages often used when compiling software from the source code.
Next, run the gcc command to make sure gcc is properly installed. Gcc is a compiler used to compile source code into binary files.
If you see a version number after the command, then gcc is installed and ready to use. If not, re-run the sudo dnf groupinstall “Development Tools” -y command above to install it.
Next, run the wget command to download the Python 3.9 source code from the Python official website. wget is a tool used to download files from the internet.
Next, run the tar command to extract the downloaded Python 3.9 source code.
tar xvf Python-3.9.7.tar.xz
Next, run the cd command to change into the source code directory that was created with the previous tar. cd is a tool that allows us to navigate (change directories) in Linux.
Once you ‘re in the source code directory, run the ./configure command to configure the Python source code for your system. The configure script will check your system for all required dependencies and install them if they’re not already installed. This can take a few minutes, so be patient.
Once the altinstall command is complete, Python 3.9 has been successfully installed on your system!
Run the python3 -V command again to verify that Python 3.9 has been installed and is working correctly.
The output should show the Python 3.9.7 version number.
Creating a Python Program
Now that you’ve installed Python 3, let’s create our first program. This section will create a simple program that prints the string “Hello, World!”
In the programming community, the Hello, World program is a tradition. It is a small program that prints a few words to show that it works, and it demonstrates a very simple process in a little “tutorial” program.
First, run the command below to create a new file called hello.py using nano. nano is a very simple text editor that is included in most Linux distributions. py is a convention that means “Python program”. You can name your file anything you want.
sudo nano hello.py
Once the text editor is open, enter the following line into it:
# This is a comment. Comments are lines in a Python program that are not executed. They are used to explain what the code does. Comments begin with a hash mark ( # ) and can span multiple lines.
# This program prints "Hello, World!" print("Hello, World!")
print() in Python is a function that prints the arguments passed to it. The “Hello, World!” string has quotes around it because quotes surround strings in Python.
Exit out of the text editor by pressing CTRL+O (the letter O) and then exit again to return to your command-line interface. Now that you made changes, save them with CTRL+X (the letter X).
With our hello.py file created, we are ready to run it! Run the python3 hello.py command to run your program.
The python3 hello.py command above will run the Python program located at the hello.py file.
Running your first program in Python should result in a nice little “Hello, World!” message printed out for you on the screen. Congratulations, you just ran your first Python program!
Congratulations, you now have Python 3 installed and ran your first program! You should now be comfortable with the basics of using a command line text editor such as nano and executing Python programs.
For more information about Python, check out its official website here.