as everyone knows ,pip It can be done to python Third party library for installation 、 to update 、 Unloading and other operations , It is very convenient . Maybe some people use it for a long time pip, But it's not clear what a package management tool is .
Today, I will give you a good talk pip, It is Python The housekeeper of the third-party library , Understand it , It will save you a lot of things . Sum up 30 individual pip Common sense and skills in use , For your reference . Like to remember to collect 、 give the thumbs-up 、 Focus on .
Complete information 、 Code 、 Technical communication , At the end of the article
from Python 3.4 Start ,pip It's built into Python in , So there is no need to install again .
If your Python Version without pip, Then you can use the following two methods to install .
(1) Enter... On the command line easy_install pip
, It is fast
(2) Download from the following website pip The installation files , Then unzip to python scripts Directory , perform python setup.py install
Can be installed
Download url :https://pypi.org/project/pip/#files
Download the file :
pip --version
If pip Version of is too low , You can upgrade the current version pip install --upgrade pip
Want to know how to use pip, as well as pip What are the features , Execute the following statement to get a detailed tutorial :pip help
Use pip Install third party libraries , Execute the following statement pip install package_name
Appoint package edition :pip install package_name==1.1.2
for instance , I want to install 3.4.1 Version of matplotlibpip install matplotlib==3.4.1
If a project needs to install many libraries , That can be installed in batches :pip install -r e:\\requirements.txt
requirements.txt
The file format is as follows :
This method is suitable for offline installation ,wheel File is the source file of the library , You can download it and install it locally .
Steps are as follows :
(1) Find the corresponding library in the following website .whl file
https://www.lfd.uci.edu/~gohlke/pythonlibs/
(2) download .whl file , Pay attention to the corresponding version
(3) stay .whl In the folder , Press Shift key + Right mouse button , open CMD Windows or PowerShell
(4) Enter the command :pip install matplotlib‑3.4.1‑cp39‑cp39‑win_amd64.whl
To complete the installation
The installed library can be uninstalled :pip uninstall package_name
Upgrade the version of the current library :pip install --upgrade package_name
pip show -f package_name
List all installed third-party libraries and corresponding versions pip list
Save the installed library information locally txt In file :pip freeze > requirements.txt
Currently installed Libraries , See which versions need to be upgraded pip list -o
Verify that the installed libraries have compatibility dependencies pip check package-name
Download the library to the local specified file , Save as whl Format pip download package_name -d " File path to save "
Many people complain pip Installing libraries is sometimes too slow , That is pip The source of the problem .
As I said before pip from PyPi Download library files from , But because of PyPi Server is abroad , Access is slow .
However, many image sources are provided in China , To replace PyPi, Like Tsinghua source 、 Douban source 、 Alicloud source, etc .
These mirror sources are backed up PyPi The data in , Because the server is in China , It's going to be a lot faster .
However, the source data of the image is lagging , For example, Tsinghua source's pypi Mirror every 5 Sync once a minute .
There are two ways to use a mirror source , Take Qinghuayuan for example :
(1) Temporary use
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package matplotlib
except matplotlib Is the name of the library to be installed , Everything else is in a fixed format
(2) Set as default
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
Set as default , In the future, the installation libraries are downloaded from Tsinghua source , And there is no need to add a mirror source URL
Attach the main image source address
tsinghua :https://pypi.tuna.tsinghua.edu.cn/simple
Alibaba cloud :http://mirrors.aliyun.com/pypi/simple/
University of science and technology of China https://pypi.mirrors.ustc.edu.cn/simple/
Huazhong University of technology :http://pypi.hustunique.com/
Shandong University of technology :http://pypi.sdutlinux.org/
douban :http://pypi.douban.com/simple/
At present, a technical exchange group has been opened , Group friends have exceeded 3000 people , The best way to add notes is : source + Interest direction , Easy to find like-minded friends
The way ①、 Send the following picture to wechat , Long press recognition , The background to reply : Add group ;
The way ②、 Add microsignals :dkl88191, remarks : come from CSDN
The way ③、 WeChat search official account :Python Learning and data mining , The background to reply : Add group