当前位置:网站首页>The use of Python PIP command

The use of Python PIP command

2020-11-10 10:44:29 Jabami Mengzi

1.pip What is it? ?

pip yes python Package management tools ,python3.4 The above versions have integrated the tool , We can do it in cmd of use pip --version/pip3 --version command ( They correspond to each other 2.X and 3.X) To determine whether to install . If you use 2.x If the old version is not installed , Please look at the next section .

2.pip Download and install of

2.1 pip download

Get into https://pypi.org/project/pip/ Select the file download in the red box

2.2 Linux Lower installation

# tar -xzvf pip-20.2.4.tar.gz       decompression 
# cd pip-20.2.4                     Enter the unzip file 
# python setup.py install          install 

2.3 windows Lower installation

The download file is the same as 2.1, After the download is completed, unzip it to get

We use it CMD Go to this directory , Input python setup.py install Command to install

If it's a re install , After the installation, we can input directly pip Confirm the installation

If this is the first installation , We also need to configure environment variables

Pictured above

such pip Just install it .

2.4 pip Update

cmd Input in

python -m pip install --upgrade pip

3.pip Use

3.1 Installation package

pip install  Installation package name 

The following prompt appears , The installation is successful

3.1.1 Set domestic image source

pip The download speed in China is not ideal , So we need to use domestic mirror source to install

  • Temporary use

pip When adding parameters -i Image source address , for example

pip install bs4 -i https://pypi.tuna.tsinghua.edu.cn/simple 

This will download from Tsinghua mirror source bs4 library

Common 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/
    • douban :http://pypi.douban.com/simple/
  • Permanent change
    • linux

modify ~/.pip/pip.conf ( No create a folder and file . Folder to add “.”, Means to hide the folder ), The contents of the document are as follows

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = mirrors.aliyun.com
    • windows

Create in user directory pip Folder , Then create it in the folder pip.ini The configuration file , Fill in the same format

3.2 Displays information about installed packages

pip show  Package name 

Pictured , Shows the name of the package , Version number , Package function , Home page of package 、 Author's contact information 、 license , Installation position , rely on .

3.3 Update package

pip install --upgrade  Package name to update 

3.3.1 Query for updatable packages

pip list --outdated

3.3.2 Batch update packages

(1) utilize pip-review Batch update of packages

cmd Enter the following command

pip install pip-review
pip-review --local --interactive

(2) utilize pip Write the following code to update

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import pip
from pip._internal.utils.misc import get_installed_distributions
from subprocess import call

for dist in get_installed_distributions():
    print(dist)
    if not 'pip' in str(dist):
        call('pip3 install --upgrade %s -i https://pypi.tuna.tsinghua.edu.cn/simple' % dist.project_name, shell=True)

3.4 Uninstall package

pip uninstall  The name of the package to be unloaded 

Pictured , We're going to unload pygame library

Input y Are you sure to uninstall , If you have the above prompt, it means that the uninstall is successful .

4.pip Argument parsing

# pip --help
 
Usage:  
 pip<command>[options]
 
Commands:
 install                     Installation package .
 uninstall                   Uninstall package .
 freeze                      Output the list of installed packages in a certain format 
 list                        List installed packages .
 show                        Show package details .
 search                      Search package , similar yum Inside search.
 wheel                      Buildwheelsfromyourrequirements.
 zip                         Not recommended .Zipindividualpackages.
 unzip                       Not recommended .Unzipindividualpackages.
 bundle                      Not recommended .Createpybundles.
 help                        Current help .
 
GeneralOptions:
 -h,--help                  Display help .
 -v,--verbose               More output , You can use at most 3 Time 
 -V,--version               Real version information and exit .
 -q,--quiet                 Minimum output .
 --log-file<path>           The way coverage records verbose Error log , Default file :/root/.pip/pip.log
 --log<path>                Don't cover records verbose Output log .
 --proxy<proxy>            Specifyaproxyintheform[user:passwd@]proxy.server:port.
 --timeout<sec>             Connection timeout ( Default 15 second ).
 --exists-action<action>   Defaultactionwhenapathalreadyexists:(s)witch,(i)gnore,(w)ipe,(b)ackup.
 --cert<path>               certificate .

 

版权声明
本文为[Jabami Mengzi]所创,转载请带上原文链接,感谢