Simple and easy-to-understand pip installation command tutorial, specific code examples are required
pip is Python’s official package management tool. Easily install, upgrade and manage Python third-party libraries. This article will introduce the installation method and common commands of pip, as well as solutions to some common problems.
Before installing pip, you need to confirm whether Python is installed. Open a terminal or command line window and enter the following command to confirm the Python version:
python --version
If version 2.x is displayed, Python 3 needs to be installed. You can go to [Python official website](https://www. python.org/downloads/) to download and install the latest version of Python.
After installing Python 3, pip should already be installed by default. Also in the terminal or command line window, enter the following command to confirm whether pip has been installed:
pip --version
If the version number of pip is displayed, it means the installation has been successful. If it doesn't show up, you need to install pip manually.
To install pip under Windows system, you need to use the official installation program of Python. In the terminal or command line window, enter the following command to install:
python get-pip.py
Hereget-pip.py
is the pip installation script, which can be downloaded from [pip official website](https: //pip.pypa.io/en/stable/installing/) download.
In macOS and Linux systems, you can use the package management tool that comes with the system to install pip. In the terminal, enter the following command to install:
sudo easy_install pip
The sudo
command is used here to obtain administrator rights to ensure that the installation process proceeds smoothly.
To install a Python package, you can use the install
command. Enter the following command in the terminal:
pip install package_name
For example, to install a package named requests
, you can enter:
pip install requests
Upgrade Installed packages can use the install
command and add the --upgrade
parameter. Enter the following command in the terminal:
pip install --upgrade package_name
For example, to upgrade the requests
package, you can enter:
pip install --upgrade requests
To uninstall the installed package For packages, you can use the uninstall
command. Enter the following command in the terminal:
pip uninstall package_name
For example, to uninstall the requests
package, you can enter:
pip uninstall requests
To view installed packages and their version numbers, you can use the list
command. Enter the following command in the terminal:
pip list
This command will list all installed packages and their corresponding version numbers.
If you want to search for a package, you can use the search
command. Enter the following command in the terminal:
pip search package_name
This command will list all packages whose package names contain the package_name
keyword.
In foreign countries where the network environment is poor, the download speed may be too slow when using pip The problem. You can increase download speed by switching pip's mirror source. You can open the pip.ini
file (in the user directory under Windows, in the ~/.pip/
directory under macOS and Linux) and find [global]
index-url
line under the section, comment it (add # symbol at the beginning of the line), and then add the following mirror source:
index-url = https://mirrors.aliyun.com/pypi/simple/
Sometimes you need to install a specified version of the package. You can add ==
and the version number after the install
command. For example:
pip install package_name==1.0.0
If you have a requirements.txt
file that contains all dependent packages and their version numbers, you can use the following Command to batch install these packages:
pip install -r requirements.txt
This article introduces the installation method and common commands of pip, and provides solutions to some common problems. By learning and mastering the use of pip, you can more easily manage Python's third-party libraries and improve development efficiency. Hope this article is helpful to everyone!
The above is the detailed content of An easy-to-follow pip installation guide. For more information, please follow other related articles on the PHP Chinese website!