List of content you will read in this article:
Even tech-enthusiastic people that are not part of the software development world, more often than not recognize the name Python. And no, we are not talking about the literal pet. What we refer to, is the programming language that, while still being used for writing programs, is most commonly used for scripting purposes. Today we will show you how to install Python on Ubuntu 18.04, however, before jumping straight into the tutorial, let us shortly introduce you to the renowned programming language.
What is Python?
Python is an open-source programming language that helps you run programs and extensions from various third-party providers on your system (or even applications you develop). Python is a general-purpose, high-level, object-oriented scripting language. It is open source and was developed in 1991 by Von Hansen in Holland.
The philosophy of its creation emphasizes the two main goals of readability of the written + shortcomings and the relative efficiency of the program. The keywords of the language are minimal and it offers a vast variety of libraries for the user to choose from.
Python isn't pre-installed on Windows, although it doesn't rule out the possibility that Windows users will find the lightweight programming language helpful. It's not as simple as just upgrading to the most recent version, so be sure you've got tools for the task.
Unlike some other common programming languages, where code blocks are defined in the parenthesis, Python uses the character spacing and forwarding of the program to specify blocks of code. This means that there are a number of identical spacing characters at the beginning of each block's lines, and this number increases in the inner code blocks. This way blocks of code are automatically organized.
What Version Would Users Require?
Regrettably, a major upgrade to Python many years ago resulted in a large break among Python releases. It may be a little perplexing for beginners, but don't worry. We'll demonstrate how to set up all of the major ones.
When you go to the Python for Windows downloads tab, you'll notice the separation right away. The registry always asks whether you want the latest Python 2 or Python 3 upgrade at the core, square, and center. It is recommended to install and run both versions simultaneously to get the most out of Python. However, if you already know which version you need for your goals, then simply stick with that one.
Getting Ubuntu and Installing Python
Visit the official website and navigate to the “Downloads” section to get Python. The most recent Python version for Ubuntu can be found on the website. Go ahead and download it.
Untar the file after downloading the tarball. You will see a couple of directories after untarring the file. The readme file is the one you'll want to look at because it contains instructions for installing Python on an Ubuntu system.
Please note: all the commands written below must be entered with root access.
Adjust the directory of the untarred Python file and execute the command below in the terminal.
cd ~/<python untarred folder>
Install python command:
sudo make install
It will make the installation of Python as Python3.
If you get an error message or warning when running
sudo ./configure, such as no compiler found, install the below library to get rid of it:
apt-get install build-essential
Also, if you get an error message or warning when running, like make not found, j run the below command to install make:
sudo apt install make
After you've installed the above libraries, such as create and build-essential, you should be able to use the install python command.
Another way to install Python is to use the apt-get commands as seen below:
In the terminal, type the following commands:
sudo apt-get update
It will ensure that Ubuntu's repositories are up to date. Then, run the following command in order to install Python 3:
sudo apt-get install python3
What is the Most Efficient Way to Execute Python Code?
Simply run the following command to run python code.
Installation of Extra Python Packages
Run the command pip3 list to watch what modules are installed in the application. It will show a list of all the modules currently installed in the environment. If you choose to install additional modules in the environment, such as the request library, you can do so with pip3 install requests. Now run the pip3 list to see if this request lib is installed in this setting.
Directory as a Package for Distribution
Within the Python project or directory, a file named init.py is used as a delivery kit. As a result, you can make this file with a single touch button. This file does not need to contain any data; it simply needs to be present in the directory to function as a package.
Utilizing Various Python Versions
You’d have two separate versions of Python on your framework if you used the alt install tool. Each installation comes with its own set of instructions.
Execute commands on every older Python 2.x version on your machine with the python button. Consider the following scenario:
Using python3 to execute a script in the newer version. Consider the following scenario:
You can install different major (3.x or 2.x) versions of Python on your device. Using the second digit to specify which version you choose to use if you have both Python 3.7.x and Python 3.8.x installed:
How to Uninstall Python
In case you no longer wish to have Python installed on your Ubuntu 18.04 system, here’s what you need to do:
First, find out what version of Python you have installed by typing:
Let’s say the output says that you have Python 3.9 installed. You can uninstall it using the following command:
sudo apt autoremove python3.9
Hence, we have successfully learned how to install Python on Ubuntu and the installation’s various functionalities. We recommend running all versions simultaneously if you want to get the most out of Python. It helps to use the most modern Python version while still operating older Python scripts and testing functionality for newer projects. However, if you're certain you only need one Python version, you may install just Python 2 or Python 3. Also, if you wish to use Python on Windows instead, check out our detailed tutorial on how to install Python on Windows.