Home > Article > Operation and Maintenance > 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
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
CentOS/RHEL systems:
sudo yum install epel-release sudo yum install python3-pip
Step 3: Verify installation
After the installation is complete, you can verify whether pip is successfully installed by running the following command:
pip3 --version
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
Upgrade package:
pip3 install --upgrade package_name
Uninstall package:
pip3 uninstall package_name
View the list of installed packages :
pip3 list
View the detailed information of a package:
pip3 show package_name
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/
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
Then, activate the virtual environment:
source myenv/bin/activate
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
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!