Home System Tutorial LINUX Easily learn to install and configure Python under Linux

Easily learn to install and configure Python under Linux

Feb 11, 2024 pm 01:30 PM
linux linux tutorial linux system Linux operating system linux command shell script python program embeddedlinux Getting started with linux linux 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
Copy after login

On Fedora:

$ sudo dnf groupinstall development
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

This command creates a new directory (I named it example) with some subdirectories.

To activate the virtual environment, enter:

$ source example/bin/activate
(example) $
Copy after login

Please note that your terminal prompt ($) now starts with the environment name.

To deactivate a virtual environment, use the deactivate command:

(example) $ deactivate
Copy after login

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 of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

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 Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1269
29
C# Tutorial
1249
24
Linux Architecture: Unveiling the 5 Basic Components Linux Architecture: Unveiling the 5 Basic Components Apr 20, 2025 am 12:04 AM

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.

How to check the warehouse address of git How to check the warehouse address of git Apr 17, 2025 pm 01:54 PM

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.

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

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.

How to run sublime after writing the code How to run sublime after writing the code Apr 16, 2025 am 08:51 AM

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.

laravel installation code laravel installation code Apr 18, 2025 pm 12:30 PM

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)

What is the main purpose of Linux? What is the main purpose of Linux? Apr 16, 2025 am 12:19 AM

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.

git software installation git software installation Apr 17, 2025 am 11:57 AM

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)

How to use VSCode How to use VSCode Apr 15, 2025 pm 11:21 PM

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

See all articles