Python combat: pip commonly used techniques

Who died went to the national crisis, as the dead suddenly, such as go! - Wei Cao Zhi, "white horse articles"

First, review the installation package information

If you want to show the machine in which the installation package has been downloaded resources, use the following command:

pip list

Second, download the installation package

Use pip download the package should be used for the longest instructions, using the following instructions to:

pip install 安装包名称

If you do not specify what version to download, the download will take the latest version, if you need to specify the version information, then followed by the version number to:

pip install requests==2.22.0

Third, the bulk download the installation package

If you downloaded a single installation package, using the above instructions can handle, but if you are experiencing relatively large projects that depend on the package with dozens of small, more than a hundred, if one is installed or a tired estimate dead. Then make bulk download is very necessary.

  1. Create a text file (the file name is not required, this file is named requirements.txt), set out in the document and version information for the installation package to download:
    Here Insert Picture Description
  2. After installing the package information is stored, enter cmd interface, go to the directory where the file requirements.txt. Execute the following command can do bulk download:
pip install -Ur requirements.txt

Fourth, upgrade

4.1.pip upgrade

  1. Check the version pip of
    us first take a look at the version pip.
pip show pip

The following is a pip on my computer version.
Here Insert Picture Description
Please note that the information at the bottom of the yellow color, which is very important. You are using pip version 7.1.2, however version 10.0.1 is available.

If the small partner after seeing this prompt, indicating pip really too old, and tips you need to update the official version, if the version pip too old, many packages can not be installed.

  1. pip upgrade
    if you need to upgrade, you can execute the following command:
pip install --upgrade pip

See Successfully word that is installed successfully, pip show pip check first step inside and then, we know there is no updated successfully.

4.2 Upgrade installation package

If there is need to upgrade the installation package, and we can pip which packages will be updated by checking, using the command:

pip list --outdated

pip will set out the current version and the latest version of the information needed to upgrade a package, with the latest version number.
Here Insert Picture Description
Just need to execute the following command can be upgraded version:

pip install --upgrade 要升级的包名

Fifth, the use of domestic sources of pypi

When you install the library files pip management tool, the default use of foreign source files, download the instruction in the use of the above network resources, download speed is very slow, sometimes even question Readtimeout connection timeout occurs. This greatly affects the download speed and our mood. Fortunately, some of the country's top research institutions have given us ready for all kinds of image, the download speed whiz.
Among them, more commonly used domestic mirroring include:
(1) Ali cloud http://mirrors.aliyun.com/pypi/simple/
(2) watercress http://pypi.douban.com/simple/
(3), Tsinghua University https : //pypi.tuna.tsinghua.edu.cn/simple/
(4) China Science and technology University http://pypi.mirrors.ustc.edu.cn/simple/
(5), Huazhong University of Science and technology http: // pypi. hustunique.com/

5.1. Resources in the country mirror

Also very convenient to use, and simply add parameters -i mirror address back to the original command, for example:

#从豆瓣的镜像中下载qrcode资源
pip install qrcode -i https://pypi.douban.com/simple 
#和豆瓣镜像库里面对比是否需要升级的安装包
pip list --outdated -i https://pypi.douban.com/simple 
#从豆瓣的镜像中升级qrcode资源
pip install --upgrade 要升级的包名 -i https://pypi.douban.com/simple
Published 19 original articles · won praise 67 · views 20000 +

Guess you like

Origin blog.csdn.net/m1090760001/article/details/104519272