程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Recommended collection. You must master the 15 tips for using Python pip

編輯:Python

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

1、 install pip

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 :

2、 see pip edition

pip --version

3、 upgrade pip

If pip Version of is too low , You can upgrade the current version
pip install --upgrade pip

4、 get help

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

5、 Installation Library

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 matplotlib
pip install matplotlib==3.4.1

6、 Batch install Library

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 :

7、 Use wheel File installation Library

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

8、 Unload Library

The installed library can be uninstalled :
pip uninstall package_name

9、 Upgrade Library

Upgrade the version of the current library :
pip install --upgrade package_name

10、 View library information

pip show -f package_name

11、 View installed Libraries

List all installed third-party libraries and corresponding versions
pip list

12、 Save the library list to the specified file

Save the installed library information locally txt In file :
pip freeze > requirements.txt

13、 View the libraries that need to be upgraded

Currently installed Libraries , See which versions need to be upgraded
pip list -o

14、 Check for compatibility issues

Verify that the installed libraries have compatibility dependencies
pip check package-name

15、 Download the library locally

Download the library to the local specified file , Save as whl Format
pip download package_name -d " File path to save "

attach : Replace pip Source

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/

Technical communication

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


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved