Easily learn to install and configure Python under Linux
In the Internet era, Python is a very popular programming language. It is widely used in data analysis, machine learning, artificial intelligence and other fields. In the Linux operating system, the installation and configuration of Python is not as simple as in Windows or MacOS. Therefore, this article will introduce in detail how to install and configure Python in a Linux system so that readers can learn it easily.

Step-by-step instructions for installing the latest Python on Linux, replacing or alongside older versions.
Python is now the most popular and commonly used programming language. Python’s simple syntax and low learning curve make it the ultimate choice for beginners and professional developers alike. Python is also a very versatile programming language. From web development to artificial intelligence, it is used almost everywhere except mobile development.
If you use Python, there's a good chance you're a developer (or want to be one), and Linux is a great platform for creating software. However, when you use Python every day, sometimes you want to use the latest version. You probably don't want to replace the default Python installation just to test your system with the latest version, so this article explains how to install the latest version of Python 3 on Linux without replacing the version provided by your distribution.
Use the python –version terminal command to check whether Python is installed, and if so, which version. If Python is not installed on your Linux system or you want to install a newer version, follow the steps below.
Step-by-step installation instructions
Step 1: First, install the development packages required to build Python
On Debian
$ sudo apt update $ sudo apt install build-essential zlib1g-dev \ libncurses5-dev libgdbm-dev libnss3-dev \ libssl-dev libreadline-dev libffi-dev curl
On Fedora:
$ sudo dnf groupinstall development
Step 2: Download the latest stable version of Python 3
Visit the official Python website and download the latest version of Python 3. Once the download is complete, you will have a .tar.xz archive ("tarball") containing the source code for Python.
Step 3: Unzip the tarball
After the download is complete, use a decompression program or the Linux tar command to decompress the compressed package, for example:
$ tar -xf Python-3.?.?.tar.xz
Step 4: Configuration script
After unzipping the Python compressed package, enter the directory where the configure script is located and execute the script using the following command in the Linux terminal:
$ cd Python-3.* ./configure
Configuration may take some time. Wait until successful completion before continuing.
Step 5: Start the build process
If you already have a version of Python installed on your system and want to install a new version of Python at the same time, use the following command:
$ sudo make altinstall
The build process may take some time.
If you want to use this version to replace the current version of Python, you should use a package manager (such as apt or dnf) to uninstall the current Python package and then install:
$ sudo make install
However, it is usually best to install software as a package (such as a .deb or .rpm file) so that the system can track and update it for you. Because this article assumes that the latest Python has not yet been packaged, you may not have this option. In this case, you can use altinstall to install Python as recommended, or refactor the existing Python package with the latest source code. This is an advanced topic and specific to your distribution, so it's outside the scope of this article.
Step 6: Verify installation
If you don’t encounter any errors, you now have the latest Python installed on your Linux system. To verify, enter one of the following commands in the terminal:
python3 --version
If the output shows Python 3.x, then Python 3 has been successfully installed.
Create a virtual environment (optional)
Python provides a package called venv (virtual environment) that helps you isolate a program directory or package from other directories or packages.
To create a virtual environment, enter the following in the Python terminal (in this example, it is assumed that your installed Python version is the 3.8 series):
python3.8 -m venv example
This command creates a new directory (I named it example) with some subdirectories.
To activate the virtual environment, enter:
$ source example/bin/activate (example) $
Please note that your terminal prompt ($) now starts with the environment name.
To deactivate a virtual environment, use the deactivate command:
(example) $ deactivate
This article introduces the installation and configuration methods of Python under Linux. By studying the content of this article, you can quickly master the skills of installing and configuring Python under Linux systems, making it easier for you to develop and run Python programs. At the same time, we also provide some practical commands and tips, hoping to help you use Python better.
The above is the detailed content of Easily learn to install and configure Python under Linux. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

There are six ways to run code in Sublime: through hotkeys, menus, build systems, command lines, set default build systems, and custom build commands, and run individual files/projects by right-clicking on projects/files. The build system availability depends on the installation of Sublime Text.

To install Laravel, follow these steps in sequence: Install Composer (for macOS/Linux and Windows) Install Laravel Installer Create a new project Start Service Access Application (URL: http://127.0.0.1:8000) Set up the database connection (if required)

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

Installing Git software includes the following steps: Download the installation package and run the installation package to verify the installation configuration Git installation Git Bash (Windows only)

Visual Studio Code (VSCode) is a cross-platform, open source and free code editor developed by Microsoft. It is known for its lightweight, scalability and support for a wide range of programming languages. To install VSCode, please visit the official website to download and run the installer. When using VSCode, you can create new projects, edit code, debug code, navigate projects, expand VSCode, and manage settings. VSCode is available for Windows, macOS, and Linux, supports multiple programming languages and provides various extensions through Marketplace. Its advantages include lightweight, scalability, extensive language support, rich features and version
