Python包管理工具pip详解:安装、升级、卸载、查看与列出已安装包的全面指南

pip

1, pip 是 Python 的 包管理工具,全称为 Pip Installs Packages

  1. pip 管理 ython 的包,包括,安装包、升级包、卸载包、查看已安装的包等

  2. 如果使用的是 Python 3.4 及以上版本,pip 通常已经默认安装

  3. 在命令行中执行指令 pip --version,如果已安装,系统会显示 pip 的版本信息


pip 基础操作

1、基本介绍
(1)安装包
pip install 【包名】
# 指定版本号进行安装

pip install 【包名】==【版本号】
(2)升级包
pip install --upgrade 【包名】
# 简写

pip install -U 【包名】
(3)卸载包
pip uninstall 【包名】
(4)查看已安装的包
pip show 【package_name】
(5)列出已安装的包
pip list
2、演示
  • 这里以 HTTP 库 requests 为例,演示 pip 基础操作
  • (1)安装包
    pip install requests
    
  • 输出结果
  • Collecting requests
      Downloading requests-2.32.3-py3-none-any.whl (64 kB)
         ---------------------------------------- 64.9/64.9 KB 3.4 MB/s eta 0:00:00
    Requirement already satisfied: charset-normalizer<4,>=2 in d:\python3.10.2\lib\site-packages (from requests) (2.0.12)
    Requirement already satisfied: certifi>=2017.4.17 in d:\python3.10.2\lib\site-packages (from requests) (2021.10.8)
    Requirement already satisfied: urllib3<3,>=1.21.1 in d:\python3.10.2\lib\site-packages (from requests) (1.26.8)
    Requirement already satisfied: idna<4,>=2.5 in d:\python3.10.2\lib\site-packages (from requests) (3.3)
    Installing collected packages: requests
    Successfully installed requests-2.32.3
    WARNING: You are using pip version 22.0.3; however, version 25.0 is available.
    You should consider upgrading via the 'D:\Python3.10.2\python.exe -m pip install --upgrade pip' command.
    
    (2)升级包
    pip install --upgrade requests
    
  • 输出结果
  • Requirement already satisfied: requests in d:\python3.10.2\lib\site-packages (2.32.3)
    Requirement already satisfied: certifi>=2017.4.17 in d:\python3.10.2\lib\site-packages (from requests) (2021.10.8)
    Requirement already satisfied: idna<4,>=2.5 in d:\python3.10.2\lib\site-packages (from requests) (3.3)
    Requirement already satisfied: urllib3<3,>=1.21.1 in d:\python3.10.2\lib\site-packages (from requests) (1.26.8)
    Requirement already satisfied: charset-normalizer<4,>=2 in d:\python3.10.2\lib\site-packages (from requests) (2.0.12)
    WARNING: You are using pip version 22.0.3; however, version 25.0 is available.
    You should consider upgrading via the 'D:\Python3.10.2\python.exe -m pip install --upgrade pip' command.
    
    (3)查看已安装的包
    pip show requests
    
  • 输出结果
  • Name: requests
    Version: 2.32.3
    Summary: Python HTTP for Humans.
    Home-page: https://requests.readthedocs.io
    Author: Kenneth Reitz
    Author-email: me@kennethreitz.org
    License: Apache-2.0
    Location: d:\python3.10.2\lib\site-packages
    Requires: certifi, charset-normalizer, idna, urllib3
    Required-by: baidu-aip
    
    (4)列出已安装的包
    pip list
    
  • 输出结果
  • Package            Version
    ------------------ ---------
    baidu-aip          2.2.18.0
    certifi            2021.10.8
    charset-normalizer 2.0.12
    cycler             0.11.0
    et-xmlfile         1.1.0
    fonttools          4.29.1
    idna               3.3
    kiwisolver         1.3.2
    matplotlib         3.5.1
    numpy              1.22.2
    openpyxl           3.0.9
    packaging          21.3
    Pillow             9.0.1
    pip                22.0.3
    pyparsing          3.0.7
    python-dateutil    2.8.2
    requests           2.32.3
    setuptools         58.1.0
    six                1.16.0
    urllib3            1.26.8
    WARNING: You are using pip version 22.0.3; however, version 25.0 is available.
    You should consider upgrading via the 'D:\Python3.10.2\python.exe -m pip install --upgrade pip' command.
    
    (5)卸载包
    pip uninstall requests
    
  • 输出结果
  • Found existing installation: requests 2.27.1
    Uninstalling requests-2.27.1:
      Would remove:
        d:\python3.10.2\lib\site-packages\requests-2.27.1.dist-info\*
        d:\python3.10.2\lib\site-packages\requests\*
    Proceed (Y/n)? Y
      Successfully uninstalled requests-2.27.1
    

    作者:我命由我12345

    物联沃分享整理
    物联沃-IOTWORD物联网 » Python包管理工具pip详解:安装、升级、卸载、查看与列出已安装包的全面指南

    发表回复