Home > Backend Development > Python Tutorial > pip installation guide: detailed tutorial to help you quickly complete the installation

pip installation guide: detailed tutorial to help you quickly complete the installation

PHPz
Release: 2024-01-16 09:59:14
Original
2063 people have browsed it

pip installation guide: detailed tutorial to help you quickly complete the installation

pip installation tutorial: Detailed steps will take you through quickly, specific code examples are required

With the popularity of Python, there are more and more third-party libraries for Python. Pip is a Python package management tool. Through pip, you can easily install, uninstall, and update Python packages, which greatly simplifies the management of Python packages.

This article will introduce the installation steps of pip and commonly used pip commands in detail, and provide specific code examples to help readers better understand.

1. Installation of pip

1. Windows system

Under Windows system, pip has been integrated into the Python installation package and can be used easily. Taking Python3.x as an example, you can install pip according to the following steps:

(1) Open the cmd command and read python3. If the following results appear, it means that Python has been installed successfully.

Python 3.x.x (default, Jan xx xxxx, xx:xx:xx)
[GCC x.x.x] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Copy after login

(2) Enter the following command in the cmd command line window to upgrade pip:

python -m pip install --upgrade pip
Copy after login

After the upgrade is completed, enter the following command to test whether pip is working properly:

pip --version
Copy after login

If the pip version number is displayed correctly, it means that pip has been installed successfully.

2. Linux system

The installation method under Linux system is slightly different. The specific steps are as follows:

(1) Open the terminal command line window and enter the following command to upgrade Python:

sudo apt-get update
sudo apt-get install python3
Copy after login

After waiting for the Python installation to complete, enter the following command to test whether Python is working properly:

python3 --version
Copy after login

If the Python version number is displayed correctly, Python has been installed successfully.

(2) Enter the following command in the terminal command line window to upgrade pip:

sudo -H pip3 install --upgrade pip
Copy after login

After the upgrade is completed, enter the following command to test whether pip is working properly:

pip3 --version
Copy after login

If the pip version number is displayed correctly, it means that pip has been installed successfully.

2. Commonly used pip commands

1. Installation

In pip, we can install the Python package through the following instructions:

pip install package_name
Copy after login

Among them, package_name refers to the name of the Python package you want to install.

For example, if we want to install the Python package NumPy, we can enter the following command:

pip install numpy
Copy after login

The above command will download the latest version of NumPy. If we want to install the specified version of NumPy, we can enter The following instructions:

pip install numpy==1.18.2
Copy after login

The 1.18.2 here represents the specified version number.

2. Uninstall

If you want to uninstall the Python package, you can use the following command:

pip uninstall package_name
Copy after login

For example, if you want to uninstall the NumPy Python package, you can enter the following command:

pip uninstall numpy
Copy after login

3. Update

If you want to update the Python package, you can use the following command:

pip install --upgrade package_name
Copy after login

For example, if you want to update the NumPy Python package, you can enter the following command :

pip install --upgrade numpy
Copy after login

4. List the installed packages

If you want to view the installed Python packages, you can enter the following command:

pip list
Copy after login

This command will list the current system All installed Python packages in it are convenient for us to manage.

5. Search

If you don’t know which package to install, you can search through the following command:

pip search package_name
Copy after login

For example, if you want to find the package used to process Excel documents in Python package, you can enter the following command:

pip search excel
Copy after login

This command will return all Python packages that contain the "excel" keyword.

Summary

This article details the installation steps of pip and common pip commands, and provides specific code examples. Through the introduction of this article, readers can better master the use of pip and manage Python packages more conveniently.

The above is the detailed content of pip installation guide: detailed tutorial to help you quickly complete the installation. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template