install python Linux

The legend of the Python programming language continues to speak for itself. Its popularity makes it the most sort-after programming language. We can definitely agree that Python is slowly becoming the jack of all trades due to its numerous applicability. Both web and mobile developers are embracing their addiction to this programming language. Moreover, its bold entrance into the world of AI (Artificial Intelligence) parades more praises to its potential.

If you are on a Linux machine and you’ve strongly considered the installation and use of Python, then you do not need the prophecy of an oracle or a seer to tell you that you are about to become a great developer. Reason? The flexible and open-source nature of the Linux OS makes it the perfect platform for developing software. Moreover, all the software and applications you will need to develop your next cool web or mobile app are already in its diverse open-source software market.

The good thing about working with python is that its version is always up to date. We are currently working with Python 3, an improvement from the Python 2.7 predecessor whose support will not go past 2020. Therefore our tutorial will focus on getting Python 3 into your Linux system because it has a stable and promising lifespan. However, before we get Python into your Linux system, you need to know who you are letting in through the front door of your Linux OS.

Interesting Python Features

As a programming language, Python is high-level, interpreted, dynamic, and open-source. These attributes make it the most versatile and dynamic programming language. In python, you can achieve both Procedural Oriented Programming and Object-Oriented Programming. Therefore, be it that you want to create a program that achieves simple or complex operations, then you should have Python on speed dial. The features that favor its existence include the following.

Easy to Code

An honest comparison between Python and other high-level programming languages like Java, Javascript, and C#, puts Python on top of this list in terms of how easy it is to learn the language. You only need a few hours or days to familiarize yourself with Python. Afterward, you will stop regarding other developers as superhuman because you, too, will be on a quest to become one.

Free and Open-Source

Anyone can freely access Python, install it, and use it from its official website. Therefore, no need to worry about a secret society trying to keep the Python code to themselves. Its open-source nature implies that the public has full access to download, use, and share it.

Object Oriented Programming (OOP)

Object-Oriented Programming (OOP) is the future of software development. It lets you write short, simple, and reusable code. The concepts enclosed in this feature include the use of objects, encapsulation, and classes. On top of being easy to code, OOP makes Python more fun to learn.

GUI Support

Three programming levels define a developer: a front-end developer, a back-end developer, or a full-stack developer. A full-stack developer masters both the front-end and back-end aspects of software development. The back-end is what you can’t see and mostly entails the main logic of a program or software. However, the front-end is the user interface we use to interact with a program or software feature.

For example, your social media platform’s log-in page is a GUI (Graphical User Interface) that qualifies as a front-end. The code associated with this feature is more of a back-end since it will perform some authentication and counter-check with a database record before letting the user access the site.

With Python, the PyQt4, PyQt5, Tk, and wxPthon modules can be imported on its interpreter and used to create the perfect GUI for the front-end developers. Therefore, this programming language also supports your front-end career.

High-Level Language

The high-level feature of Python gives it some flexibility tweaks when writing or coming up with programs. A low-level language would require that you have prior knowledge of your machine’s architecture and memory management schematics. However, Python gives us a free pass as it only concerns itself with empowering us to write quality code.

Integrated By Nature

This statement means that after you run your code, the Python interpreter will go through your code line by line as it executes them. Other high-level programming languages will execute the user-written codes in blocks. You might think that the approach by other languages makes them faster and superior to Python. However, there is an aspect of efficiency to Python’s take on the line-by-line code execution approach.

This feature makes Python a more efficient debugger and, therefore, quickly informs a developer about the exact point that prevented the program code from executing correctly. Another advantage to this Python feature is the immediate byte-code conversion of a Python program code before its execution. It saves on runtime because of easy code execution.

Highly Portable

The Python program code you created and executed on your Linux system can be transferred to a friend’s or colleague’s Windows or Mac OS to preview or brainstorm. You do not have to worry about being on the same operating system when working on a Python group project. Moreover, the code structure will not be affected, unlike in programming languages like C and C++ that do not support code portability.

Dynamically Typed Language

To understand Python’s dynamic nature, we have to relate it to school life or college life scenario where you were introduced to programming. If you touched on C and C++ programming languages, you might have noticed their program code needed a specific structure to execute successfully. You had to declare a variable, initialize a variable, and then use it in a class before a program execution took place.

Python, however, does not have to adhere to these rules. It does not need an advanced variable declaration as a variable is declared only when it needs to be used by a function or class. Moreover, there is no need to specify a variable type as it will know the variable type you are using based on the value you assign it.

Extensive Array of Library

What is a library? A library is an already compiled code that performs a specific function. It prevents a user from re-inventing the wheel regarding commonly used functionalities like calendar and date functions and performing basic mathematical operations. Therefore, you will not want to stress yourself on calculating the volume of a sphere when a Python library can achieve the functionality for you. Using such Python libraries is simple, and the first step is to import them into your code editor.

Supports Other Languages

Since the C programming language was the platform used to create Python, we can regard it as its parent. The strong roots Python has with C makes it an extensible programming language. Therefore you can execute a code written in C, C#, and Java through a Python interpreter. We can also use the C and C++ platforms to write Python code. This level of versatility is unmatched in other coding platforms. How you use this feature to write awesome multi-language programs will depend on your creativity.

Python Installation on Ubuntu, Fedora, and Manjaro

Since our main business on this article piece is successfully installing Python on our Linux systems, we will not let ourselves get carried away too far with the flirtatious features Python has to offer. However, other than the mentioned marketable applications of Python at the beginning o the article, it also has an undisputed strength in scripting, data analysis, machine learning, and automation. Since Linux is a big household name that hosts various distros, we are going to focus on three main siblings in this household. They are, namely, Ubuntu, Fedora, and Manjaro.

Python 3 Installation on Ubuntu

The first approach to this guide is to ensure our Ubuntu system is in a healthy state. Therefore, you will need to update and upgrade your Ubuntu OS so that the Python system that gets shipped during its installation is up-to-date. First, ensure that you are a Sudoer user or have Sudo privileges. The Ubuntu system you are using will allow you to run the necessary update and upgrade commands.

Step 1: Update and Upgrade your System

Run the following command sequences:

sudo apt update
sudo apt -y upgrade

Step 2: Check the Python Version You Have

By default, you might already be having Python installed on your system. So it will be safe to check first before we proceed. You can use the following command sequences to check whether you have Python 2 or Python 3 on your Ubuntu system. If you have Python 2, you need to install Python 3 because Python 2 is a redundant version and loses support from 2021.

python --version //checks for Python 2 version
python3 --version //checks for Python 3 version

Step 3: Install Python 3

sudo apt install python 3.6

Step 4: Install pip tool

This tool is effective in the management of Python’s software packages. Therefore, your project might need the use of a specific library or module. The pip tool will be useful in installing the packages associated with the library or module you need.

sudo apt install -y python3-pip

Therefore, if you want to install a package, you will run the following command:

pip3 install package_name

The above package_name could be Django, a popular framework for web development or Numpy, a useful tool for scientific computing.

Step 5: Install additional tools

These tools ensure your development environment remains robust so that you do not later have to run back to the internet to look for them.

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

Step 6: Install virtual environment (venv)

The virtual environment plays a significant role in isolating your Python project development environments. Your python projects that work with different pip-installed package modules and libraries do not have to mix.

sudo apt install -y python3-venv

Step 7: Creating, Activating, and Deactivating your Virtual Environment

The following three command sequences will create, activate, and deactivate your installed virtual environment, respectively.

python3 -m venv myvenv
source myenv/bin/activate

The command below has a prefix of myenv because the virtual environment is activated. Therefore, any library packages or modules you install under this environment will only work under this environment. After we execute the command below to deactivate myenv the prefix will disappear.

(myenv) tuts@CodeUnderscored:~$ deactivate

You can create more than one virtual environments and use them for different projects you do not want to interfere with one another. For example, you can run two development server instances on two different virtual environments. Just make sure they are interacting through different ports.

Python 3 Installation on Fedora

When in a Fedora system, you will first need to adhere to some prerequisites rules before you can proceed and install Python 3 on your system. Think of them as the requirements that will support the installation of Python 3 on your fedora OS.

Step 1: Installing the prerequisites packages

The following command should get everything comfortably installed on your Fedora OS. The first command gets your OS up-to-date and then install the needed packages.

sudo dnf update
sudo yum install gcc openssl-devel bzip2-devel libffi-devel

Step 2: Downloading Python

Download Python 3 latest version from its official site.

cd /opt
wget https://www.python.org/ftp/python/3.8.6/Python-3.8.6.tgz

Step 3: Extract the Python package you downloaded

tar xzf Python-3.8.6.tgz

Step 4: Compile Python 3 Source Code

cd Python-3.8.6
sudo ./configure --enable-optimizations
sudo make altinstall

The make altinstall command protects the usr/bin/python, Python’s default binary file, from being replaced during the installation process.

Step 5: Confirm the installation of Python 3

The final phase is to check whether the Python 3 package we downloaded is active on your Fedora system. To do so, run the following command.

python3.8 -V

You should get an output like the one below

Python 3.8.6

Python 3 Installation on Manjaro

The Manjaro distro, upon its installation on your machine, comes fully equipped with a Python version. This distro is part of the Arch Linux family and therefore shares their command syntax. Since this article’s objective is to have the OS running with Python 3, we will have to check the current Python version on our Manjaro OS and provide an alternative means of making an upgrade to Python 3 if the current version does not suite us.

Step 1: Update your Manjaro System

sudo pacman -Syyu

The -Syyu portion of the above command works with the pacman package manager for Manjaro. Therefore, the located and downloaded packages from this command will force-install and force-update the installation database. Therefore, a redundant python version on your system should upgrade once a system update is initialized and executed.

Step 2: Check current Python version

python -V

If the results of the above command do not output python 3, we should proceed to have it installed in your system.

Step 2: Install Python 3

sudo pacman -S python

This command enables you install the latest available Python version on your Manjaro system.

Step 3: Confirm Python 3 Installation

python -V

An output with the installed Python 3 version should follow.

Python 3.x.x

Final Note

The successful installation of the latest stable Python version is important for your Linux system’s optimal performance, especially for an aspiring developer. However, a normal Linux user will need a stable python version to use the many open-source software and applications Linux offers. Some of these apps will not run without the installation of Python on your Linux system. The effectiveness and usefulness of Python go beyond our software development goals.

Similar Posts

Leave a Reply

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