Python is a versatile programming language widely used for various purposes, i.e., scientific computing, data analysis, and web development. It is often considered one of the best programming languages for beginners, but also widely used by experienced developers due to its vast array of libraries and frameworks. Python is a primary scripting language for Ubuntu and many other Linux distributions, which makes it a catalyst for various operations on Ubuntu.
This article will discuss:
In Ubuntu, Python, and Python3 refer to different versions of the Python programming language. The code written in Python3 may not work with Python2 and vice versa. Therefore, it is necessary to check the version of installed Python before using it:
The output displays that “python” is not installed in the system.
Python3 comes by default with Ubuntu 22.04. To check the installed version of “python3”, run the following command:
The output returns that “Python 3.10.6” is currently installed in the system.
The “python-is-python3” package redirects Python to Python3 by creating a symbolic link of Python3 for Python. This utility is available on the default repository of Ubuntu and can be installed using the command:
After installing the “python-is-python3” package, the “python” command will show the Python3 (as per the interpreter “/usr/bin/python3”):
The output displays the current version of Python as “Python 3.10.6”.
Many applications and system packages rely on the default version of Python. If you remove the default Python, the packages and system utilities associated with Python will stop functioning, and the system will crash.
Let us show you the important utilities that will be removed with the default Python version:
Look at the above screenshots. Various system utilities, such as Ubuntu Desktop, Ubuntu-minimal, gdm3 (GNOME Display Manager), and other GNOME-based packages, will be removed with the command.
As discussed earlier, the default version of Python on Ubuntu 22.04 is harmful to uninstall. However, if you have removed it accidentally then it can be fixed by following the steps mentioned in this section.
Once Python is uninstalled, you will get the following interface, which is tty1:
Now, all the fixing will be carried out using this tty1 support. If you are unable to get the tty support, you can use the shortcuts “CTRL+ALT+F1 or CTRL+ALT+F3” to invoke it.
Now, let’s move towards the steps.
Step 1: Fix the Internet Issue
Before proceeding, enable internet access on your Ubuntu system using the command which will allow the client to connect to the DHCP server:
Then, configure the network with the DHCP server via the command:
Step 2: Fix the Missing Dependencies
Now, use the command to locate and install the missing dependencies:
Step 3: Install “ubuntu-Desktop”
After that, run the following command to install the Ubuntu-Desktop package to have the GUI and the CLI support on your Ubuntu 22.04:
As soon the installation is completed, the login screen will appear automatically:
Step 4: Verify the Default Python
Log in to the system and run the following command to verify the availability of the default Python3:
The output confirms that with the installation of Ubuntu-Desktop, the Python is restored.
It is suggested to reinstall the package “python-is-python3” to map the Python3 on Python:
Now, check the Python version:
Python has now the same version as Python3.
Note: The uninstallation of default Python is not recommended as there are a lot of utilities that are dependent on default python.
The source packages of Python can be obtained from its official website. These source files include the latest stable version and Python prerelease. This section will describe the steps to installing a specific Python version from source files.
Prerequisite Step: Install Dependencies
The following dependencies are recommended to be installed before proceeding with the Python’s installation:
Step 1: Download the Source Files
First, download the source files of the specific version that you want to install as we did here for “Python3.11.1”:
Note: Navigate to the link to choose the Python version.
Step 2: Extract the Python Source Files
Navigate to the directory (in our case, it is the current directory) where the source files are downloaded and extract it using the “-xvf” flag of the “tar” command:
Step 3: Configure Python
Switch to the directory of the extracted files and then run the configure script with the “–enable-optimizations” option for the best performance of the Python environment:
Step 4: Compile the Source Files
Now, compile the source files using the “make” utility to build an executable (binaries that are recognized by the machine) for the Python package:
Step 5: Install Python
Once the files are compiled, you can use the following command to install Python from the binaries:
After the successful execution, run the following command to verify the installation:
The output shows that the Python 3.11.1 version has been installed.
To install Python on Ubuntu 22.04, you can use an apt package manager and compile/build the source files. By using APT, execute the “sudo apt install python
In this article, we will see how to Install Google Cloud BigQuery Python client library…
Nov 15,2024 Wallpaper Contest for Xfce 4.20 open for voting The submission phase for the…
MicroCloud 2.1.0 LTS is now available, expanding the number of Canonical infrastructure solutions with a…
Canonical is thrilled to be joining forces with Dell Technologies at the upcoming Dell Technologies…
In today’s massive private mobile network (PMN) market, one of the most common approaches to…
Welcome to the Ubuntu Weekly Newsletter, Issue 865 for the week of November 3 –…