search
HomeSystem TutorialLINUXEasily learn to install and configure Python under Linux

Easily learn to install and configure Python under Linux

Feb 11, 2024 pm 01:30 PM
linuxlinux tutoriallinux systemLinux operating systemlinux commandshell scriptpython programembeddedlinuxGetting started with linuxlinux learning

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.

Easily learn to install and configure Python under Linux

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!

Statement
This article is reproduced at:良许Linux教程网. If there is any infringement, please contact admin@php.cn delete
Warehouse: A GUI for Effortlessly Handling Flatpak AppsWarehouse: A GUI for Effortlessly Handling Flatpak AppsMay 09, 2025 am 11:30 AM

A GUI for Effortless Flatpak Management: Introducing Warehouse Managing a growing collection of Flatpak applications can be cumbersome using only the command line. Enter Warehouse, a user-friendly graphical interface designed to streamline Flatpak a

8 Powerful Linux Commands to Identify Hard Drive Bottlenecks8 Powerful Linux Commands to Identify Hard Drive BottlenecksMay 09, 2025 am 11:03 AM

This article provides a comprehensive guide to identifying and resolving hard drive bottlenecks in Linux systems. Experienced server administrators will find this particularly useful. Slow disk operations can severely impact application performance,

4 Best QR Code Generators for Linux Users4 Best QR Code Generators for Linux UsersMay 09, 2025 am 10:27 AM

Efficient QR code generation tool under Linux system In today's digital world, QR codes have become a way to quickly and conveniently share information, simplifying data access from URLs, texts, contacts, Wi-Fi credentials, and even payment information. Linux users can use a variety of tools to create QR codes efficiently. Let's take a look at some popular QR code generators that can be used directly on Linux systems. QRencode QRencode is a lightweight command line tool for generating QR codes on Linux. It is well-received for its simplicity and efficiency and is popular with Linux users who prefer direct methods. Using QRencode, you can use the URL,

elementary OS 8: A User-Friendly Linux for macOS and Windowselementary OS 8: A User-Friendly Linux for macOS and WindowsMay 09, 2025 am 10:19 AM

Elementary OS 8 Circe: A Smooth and Stylish Linux Experience Elementary OS, a Ubuntu-based Linux distribution, has evolved from a simple theme pack into a fully-fledged, independent operating system. Known for its user-friendly interface, elegant de

40  Linux Commands for Every Machine Learning Engineer40 Linux Commands for Every Machine Learning EngineerMay 09, 2025 am 10:06 AM

Mastering Linux is crucial for any machine learning (ML) engineer. Its command-line interface offers unparalleled flexibility and control, streamlining workflows and boosting productivity. This article outlines essential Linux commands, explained fo

Arch Linux Cheat Sheet: Essential Commands for BeginnersArch Linux Cheat Sheet: Essential Commands for BeginnersMay 09, 2025 am 09:54 AM

Arch Linux: A Beginner's Command-Line Cheat Sheet Arch Linux offers unparalleled control but can feel daunting for newcomers. This cheat sheet provides essential commands to confidently manage your system. System Information & Updates These com

How to Install Scikit-learn for Machine Learning on LinuxHow to Install Scikit-learn for Machine Learning on LinuxMay 09, 2025 am 09:53 AM

This guide provides a comprehensive walkthrough of installing and using the Scikit-learn machine learning library on Linux systems. Scikit-learn (sklearn) is a powerful, open-source Python library offering a wide array of tools for various machine l

How to Install Kali Linux Tools in UbuntuHow to Install Kali Linux Tools in UbuntuMay 09, 2025 am 09:46 AM

This guide explains how to leverage Docker for accessing Kali Linux tools, a safer and more efficient alternative to outdated methods like Katoolin. Katoolin is no longer actively maintained and may cause compatibility problems on modern systems. Do

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software