Quick start guide to installing pip on Linux

WBOY
Release: 2024-01-17 08:43:06
Original
1405 people have browsed it

Quick start guide to installing pip on Linux

Quick Start: A concise tutorial for installing pip on Linux, specific code examples are required

As a commonly used Python package management tool, pip can help developers quickly and easily Install, upgrade, and uninstall Python packages. However, installing pip on Linux systems may be slightly different from other operating systems, so this article will provide you with a concise tutorial to help you quickly get started with pip installation on Linux systems.

Step 1: Update the system

Before installing pip, it is recommended that you update the system first to ensure that you are using the latest software packages and libraries. Execute the following command in the terminal to update the system:

sudo apt-get update sudo apt-get upgrade
Copy after login

Step 2: Install pip

On Linux systems, pip is installed through the package manager. Depending on the Linux distribution you are using, you can use different commands to install pip, as follows:

Debian/Ubuntu systems:

sudo apt-get install python3-pip
Copy after login

CentOS/RHEL systems:

sudo yum install epel-release sudo yum install python3-pip
Copy after login

Step 3: Verify installation

After the installation is complete, you can verify whether pip is successfully installed by running the following command:

pip3 --version
Copy after login

If the installation is successful, the version number of pip will be displayed.

Step 4: Use pip to install Python packages

Once pip is installed successfully, you can start using it to install Python packages. The following are some commonly used pip command examples:

Install package:

pip3 install package_name
Copy after login

Upgrade package:

pip3 install --upgrade package_name
Copy after login

Uninstall package:

pip3 uninstall package_name
Copy after login

View the list of installed packages :

pip3 list
Copy after login

View the detailed information of a package:

pip3 show package_name
Copy after login

Step 5: Configure PIP mirror source (optional)

Sometimes, due to network environment reasons, from The default pip source download and installation package may be slow or unstable. In order to solve this problem, you can switch the pip source to a domestic mirror source, such as Alibaba Cloud, Tsinghua University, University of Science and Technology of China, etc.

For example, to switch the pip source to the Alibaba Cloud image, you can execute the following command:

pip3 install pip -U pip3 config set global.index-url https://mirrors.aliyun.com/pypi/simple/
Copy after login

Step 6: Use a virtual environment (optional)

During the development process, Using a virtual environment can help you isolate the Python packages your project depends on to avoid conflicts with other projects. To use a virtual environment, you can use the venv module to create a new virtual environment as follows:

python3 -m venv myenv
Copy after login

Then, activate the virtual environment:

source myenv/bin/activate
Copy after login

When using pip to install the package, it will automatically Install it into this virtual environment.

Step 7: Exit the virtual environment

When you complete the development of the project or no longer need the virtual environment, you can use the following command to exit the virtual environment:

deactivate
Copy after login

Summary

Through this concise tutorial, you should have mastered the basic steps and common commands for installing pip on a Linux system. At the same time, we also introduced how to configure pip sources and use virtual environments to make your Python development more efficient and reliable. I hope this article can help you learn pip installation on Linux systems!

The above is the detailed content of Quick start guide to installing pip on Linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Latest Articles by Author
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!