python包管理工具pip使用手册
pip是什么?
pip 是 Python 标准库管理器,也就是一个工具让你安装不同的类库来使用。
当你要安装某些类库时,都会使用 pip,那 pip 除了安装类库之外,还能做什么呢?
首先,我们进入 cmd终端,输入 pip,查看当前 pip 的命令集合。
$ pip
Usage:
  pip <command> [options]
Commands:
  install                     Install packages.
  download                    Download packages.
  uninstall                   Uninstall packages.
  freeze                      Output installed packages in requirements format.
  list                        List installed packages.
  show                        Show information about installed packages.
  check                       Verify installed packages have compatible dependencies.
  config                      Manage local and global configuration.
  search                      Search PyPI for packages.
  cache                       Inspect and manage pip's wheel cache.
  index                       Inspect information available from package indexes.
  wheel                       Build wheels from your requirements.
  hash                        Compute hashes of package archives.
  completion                  A helper command used for command completion.
  debug                       Show information useful for debugging.
  help                        Show help for commands.
General Options:
  -h, --help                  Show help.
  --debug                     Let unhandled exceptions propagate outside the
                              main subroutine, instead of logging them to
                              stderr.
  --isolated                  Run pip in an isolated mode, ignoring environment
                              variables and user configuration.
  --require-virtualenv        Allow pip to only run in a virtual environment;
                              exit with an error otherwise.
  -v, --verbose               Give more output. Option is additive, and can be
                              used up to 3 times.
  -V, --version               Show version and exit.
  -q, --quiet                 Give less output. Option is additive, and can be
                              used up to 3 times (corresponding to WARNING,
                              ERROR, and CRITICAL logging levels).
  --log <path>                Path to a verbose appending log.
  --no-input                  Disable prompting for input.
  --proxy <proxy>             Specify a proxy in the form
                              [user:passwd@]proxy.server:port.
  --retries <retries>         Maximum number of retries each connection should
                              attempt (default 5 times).
  --timeout <sec>             Set the socket timeout (default 15 seconds).
  --exists-action <action>    Default action when a path already exists:
                              (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.
  --trusted-host <hostname>   Mark this host or host:port pair as trusted, even
                              though it does not have valid or any HTTPS.
  --cert <path>               Path to PEM-encoded CA certificate bundle. If
                              provided, overrides the default. See 'SSL
                              Certificate Verification' in pip documentation
                              for more information.
  --client-cert <path>        Path to SSL client certificate, a single file
                              containing the private key and the certificate in
                              PEM format.
  --cache-dir <dir>           Store the cache data in <dir>.
  --no-cache-dir              Disable the cache.
  --disable-pip-version-check
                              Don't periodically check PyPI to determine
                              whether a new version of pip is available for
                              download. Implied with --no-index.
  --no-color                  Suppress colored output.
  --no-python-version-warning
                              Silence deprecation warnings for upcoming
                              unsupported Pythons.
  --use-feature <feature>     Enable new functionality, that may be backward
                              incompatible.
  --use-deprecated <feature>  Enable deprecated functionality, that will be
                              removed in the future.
| commands | 原指令解释 | 翻译 | 
|---|---|---|
| install | Install package | 安装python包 | 
| download | download package | 下载python包 | 
| uninstall | Uninstall package | 卸载python包 | 
| freeze | Output installed package in requirements format | 按照一定格式输出安装好的包 | 
| list | List installed packages | 列出安装了的python包 | 
| show | Show information about installed packages | 详细展示安装了的python包的信息 | 
| check | Verify installed packages have compatible dependencies | 检验安装了的python包有相互依赖性 | 
| search | Search PyPI for packages | 查询python包的镜像依赖(PyPI) | 
| wheel | Builds wheels from your requirements | 建立你的需求的安装路径 | 
| hash | Compute hashes of package archives | 计算包装档案的关键字 | 
| completion | A helper command used for command completion | 一个帮助指令用作指令完成 | 
| help | Show help for commands | 显示该项指令如何使用 | 
pip --version
只要在终端输入 pip --version 或者 pip -V 就能得到当前系统安装的 pip 版本,同时也会知道对应的 Python 版本。
$ pip --version
pip 22.0.4 from /Users/niuben/opt/anaconda3/lib/python3.9/site-packages/pip (python 3.9)
$ pip -V
pip 22.0.4 from /Users/niuben/opt/anaconda3/lib/python3.9/site-packages/pip (python 3.9)
pip升级
sudo python3 -m pip install --upgrade pip
pip list 查询当前已安装类库
$ pip list
Package                            Version
---------------------------------- --------------------
alabaster                          0.7.12
anaconda-client                    1.9.0
anaconda-navigator                 2.1.1
anaconda-project                   0.10.1
anyio                              2.2.0
appdirs                            1.4.4
applaunchservices                  0.2.1
appnope                            0.1.2
appscript                          1.1.2
argh                               0.26.2
argon2-cffi                        20.1.0
arrow                              0.13.1
asn1crypto                         1.4.0
astroid                            2.6.6
astropy                            4.3.1
async-generator                    1.10
atomicwrites                       1.4.0
attrs                              21.2.0
autopep8                           1.5.7
Babel                              2.9.1
在安装包之前,先看一下这个包否已安装,或者当前包的版本,使用如下命令:
pip list -o
pip install 安装类库
默认情况下 pip 使用的是国外的镜像,在下载的时候速度非常慢,下载速度是几kb或者几十kb,花费的时间比较长,请移步查看 python 更新pip镜像源
安装类库时,只需要使用 pip install --upgrade 包名称 就可以安装对应的类库了
如果没有对应的类库,就会安装失败,提示找不到
$ pip install --upgrade zipp     # 由于已经安装,会提示已安装并说明类库安装位置
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Requirement already satisfied: zipp in ./opt/anaconda3/lib/python3.9/site-packages (3.6.0)
$ pip install --upgrade zip111     # 输入错误的包名,会提示错误,找不到
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', timeout('_ssl.c:1112: The handshake operation timed out'))': /pypi/simple/zipp111/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', timeout('_ssl.c:1112: The handshake operation timed out'))': /pypi/simple/zipp111/
ERROR: Could not find a version that satisfies the requirement zipp111 (from versions: none)
ERROR: No matching distribution found for zipp111
有时候我们需要安装指定版本的类库,新版本有时候会出现一些兼容问题,导致冲突
这时候安装类库包时,可以使用 pip install --upgrade 包名称==版本号 指定版本号
$ pip install --upgrade zipp==3.6.0
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting zipp==3.6.0
  Downloading https://mirrors.aliyun.com/pypi/packages/bd/df/d4a4974a3e3957fd1c1fa3082366d7fff6e428ddb55f074bf64876f8e8ad/zipp-3.6.0-py3-none-any.whl (5.3 kB)
Installing collected packages: zipp
  Attempting uninstall: zipp
    Found existing installation: zipp 3.8.0
    Uninstalling zipp-3.8.0:
      Successfully uninstalled zipp-3.8.0
Successfully installed zipp-3.6.0
有时候安装完类库时,会提示你升级 pip,当然升级下最好啦
python3 -m pip install –upgrade pip => 升級 pip 套件
pip show 了解指定类库资讯
使用 pip show <包名> ,可以更加详细了解类库相关说明
pip show Babel
Name: Babel
Version: 2.9.1
Summary: Internationalization utilities
Home-page: http://babel.pocoo.org/
Author: Armin Ronacher
Author-email: armin.ronacher@active-4.com
License: BSD
Location: /Users/niuben/opt/anaconda3/lib/python3.9/site-packages
Requires: pytz
Required-by: jupyterlab-server, Sphinx
pip uninstall 卸载类库
当你不需要这个类库或者觉得太占空间时,可以使用 pip uninstall <类库名> ,卸载对应的类库
在删除的时候,会询问你一次,是否确定删除
如果真的删除了,需要时,可以再通过 pip install <类库名> 安装回来
$ pip uninstall zipp
Found existing installation: zipp 3.6.0
Uninstalling zipp-3.6.0:
  Would remove:
    /Users/niuben/opt/anaconda3/lib/python3.9/site-packages/zipp-3.6.0.dist-info/*
    /Users/niuben/opt/anaconda3/lib/python3.9/site-packages/zipp.py
Proceed (Y/n)? y
  Successfully uninstalled zipp-3.6.0
$ pip install zipp
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting zipp
  Downloading https://mirrors.aliyun.com/pypi/packages/80/0e/16a7ee38617aab6a624e95948d314097cc2669edae9b02ded53309941cfc/zipp-3.8.0-py3-none-any.whl (5.4 kB)
Installing collected packages: zipp
Successfully installed zipp-3.8.0
pip freeze 列出所有安装类库
pip list 不就能列出所有安装的类库吗?那为什么还有 pip freeze 呢?
pip list 列出的是所有安装的类库包,可并不是所有的类库包都可以删除的,例如:pip、setuptools等等
它们就像是手机中预载的系统app,没有办法删除,而通过 pip freeze 可以取出自己安装过的类库包
当然如果一定要用 pip freeze 来显示所有包,可以加上参数 --all ,就可以啦
pip freeze > requirements.txt 将本地安装包导出写入文本
当我们换电脑或者使用新的系统来跑当前 Python 相同的代码时,可以一键安装对应的类库,以及轻松搞定类库版本问题
换系统时,有时候会因为某些类库或者版本问题,造成冲突或者异常,不如直接导出到 txt 文本中,再通过安装的方式,快速复制一套 Python 开发环境,省时又省力。
$ pip freeze > requirements.txt  # 把电脑的已安装的类库包,导出到 requirements.txt
$ cat requirements.txt  # 查看 requirements.txts 內容
cat requirements.txt
alabaster @ file:///home/ktietz/src/ci/alabaster_1611921544520/work
anaconda-client @ file:///opt/concourse/worker/volumes/live/866d4dd0-ff5b-4d0b-718d-0267a3b10e06/volume/anaconda-client_1635342573767/work
anaconda-navigator==2.1.1
anaconda-project @ file:///tmp/build/80754af9/anaconda-project_1626085644852/work
anyio @ file:///opt/concourse/worker/volumes/live/96440bbe-d2f1-4a9e-5edf-600248ff38bd/volume/anyio_1617783321037/work/dist
appdirs==1.4.4
applaunchservices @ file:///Users/ktietz/demo/mc3/conda-bld/applaunchservices_1630511705208/work
appnope @ file:///opt/concourse/worker/volumes/live/6ca6f098-d773-4461-5c91-a24a17435bda/volume/appnope_1606859448531/work
appscript @ file:///opt/concourse/worker/volumes/live/00049ed6-6263-4a6e-72b9-9d990f6e2f07/volume/appscript_1611427000595/work
argh==0.26.2
argon2-cffi @ file:///opt/concourse/worker/volumes/live/38e8fb2b-1295-4bdf-4adf-b20acbe4d91b/volume/argon2-cffi_1607022498041/work
arrow @ file:///opt/concourse/worker/volumes/live/1c202787-83f7-4b70-6d98-b40769f597f4/volume/arrow_1617737667847/work
asn1crypto @ file:///tmp/build/80754af9/asn1crypto_1596577642040/work
...
这时候在另一套新系统终端上执行 pip install -r requirements.txt,就能快速将旧系统原有的类库安装到新系统上了。
pip install -r requirements.txt
pip 整理本地安装类库
可以先执行 pip freeze > requirements.txt 导出所有已安装类库包,然后再修改 requirements.txt,将需要删除的类库保留,然后执行 pip uninstall -r requirements.txt 就能快速删除指定的类库了,如果需要恢复,再执行pip install -r requirements.txt 即可。
python包管理工具pip使用手册的更多相关文章
- python 包管理工具 pip 的配置
		
近几年来,python的包管理系统pip 越来越完善, 尤其是对于 windows场景下,pip大大改善了python的易用性. https://www.cnblogs.com/yvivid/p/pi ...
 - Python包管理工具pip的基本使用
		
1.简介 pip 是一个Python包管理工具,主要是用于安装 PyPI 上的软件包,可以替代 easy_install 工具. 2.pip安装 如果你安装的Python 2 >=2.7.9 或 ...
 - python 包管理工具pip安装与使用
		
pip是python的一个包管理工具,与之类似的工具还有easy_install.根据官网的说法 如果你的python版本在Python 2 >=2.7.9 or Python 3 >=3 ...
 - python入门:python包管理工具pip的安装
		
pip 是一个安装和管理 Python 包的工具 , 是 easy_install 的一个替换品. distribute是setuptools的取代(Setuptools包后期不再维护了),pip是e ...
 - Python包管理工具——pip
		
目录 Python pip pip相关命令 解决pip相关问题 Python pip Python最让人的喜欢的就是它有丰富的类库和各种第三方的包,而对于这些包的下载.删除等管理操作,就要用到包管理工 ...
 - Linux服务器中安装python包管理工具pip
		
pip是python的包管理工具,python的强大之处除了在于语法的简练,还有就是对众多的库支持了. 1.下载pip包管理工具 链接地址:https://pypi.python.org/pypi/p ...
 - $python包管理工具pip的安装和使用
		
pip是python的一个非常好用的包管理工具,可以用来很方便地安装和管理各种三方库,本文对其基本用法进行介绍. 安装pip Windows系统上安装 python 2.7.9及以上版本的window ...
 - Python 包管理工具 pip 与 conda
		
简介 pip是接触 python 后最早认识的包管理工具.通过使用 pip 能够自动下载和解决不同 python 模块的依赖问题,使 python 的配置过程变得简单. 与 pip 类似,conda ...
 - python包管理工具pip
		
你可以使用一个名为 pip 的程序来安装.升级和移除软件包.默认情况下 pip 将从 Python Package Index <https://pypi.org> 安装软件包.你可以在浏 ...
 - Python包管理工具pip安装
		
Python版本在2.7.9+以上的都自带pip无需安装,但在CentOS 7里面自带的Python是2.7.5,所以需要单独安装. 安装: curl https://bootstrap.pypa.i ...
 
随机推荐
- Qt编写地图综合应用20-多浏览器内核
			
一.前言 本人写Qt程序这么多年,比较喜欢支持多个Qt版本,尤其是钟情于支持任意Qt版本+任意系统+任意编译器,这句话说起来简单其实实现起来就不容易了,首先你得有个很多版本的测试环境,起码十几个Qt环 ...
 - Qt 中实现系统主题感知
			
[写在前面] 在现代桌面应用程序开发中,系统主题感知是一项重要的功能,它使得应用程序能够根据用户的系统主题设置(如深色模式或浅色模式)自动调整其外观. Qt 作为一个跨平台的C++图形用户界面应用程序 ...
 - C#反序列化时,反射类型“XXX”时出错,提示:InvalidOperationException
			
C#反序列化时,反射类型"XXX"时出错,提示:InvalidOperationException的原因是因为: 一个类必须至少有一个空的默认构造函数,才能由XmlSerializ ...
 - 前端学习openLayers配合vue3(圆形形状的绘制)
			
上节课我们学了加载了矢量图片,这节我们来学绘制圆形 关键代码,第一段呢是设置圆点的操作,第二步是点击地图获取地图位置来设置圆点,ol还有很多类,各种形状的 //设置圆点 // let anchorLa ...
 - WPF 取消在触屏上点击按下不松开会出现矩形背景的效果
			
加个属性: btn.SetValue(Stylus.IsPressAndHoldEnabledProperty,false); 或者在样式里设置: <Style x:Key="MyB ...
 - w3cschool-Nginx 入门指南
			
https://www.w3cschool.cn/nginx/ Nginx 的特点 Nginx 做为 HTTP 服务器,有以下几项基本特性: 处理静态文件,索引文件以及自动索引:打开文件描述符缓冲. ...
 - http 协议请求响应模型
			
http 协议请求响应模型(一次请求生命周期或简单的软件分层) 场景: 登录 1.客户端发起请求到api接口层 1.1用户在客户端填写用户名和密码,点击登录,发送请求. 2.api接收到客户端发起的用 ...
 - 远程连接Windows
			
远程桌面连接 限制 1.同网段 (1)服务器关闭防火墙 (2)服务器端 右键点击'我的电脑'进入'属性'点击左侧菜单栏中的'远程设置': 把远程桌面选项设置成'允许运行任意版本远程桌面的计算机连接'. ...
 - 推荐一款非常好用的在线 SSH 管理工具
			
前言 SSH工具在远程连接.文件传输.远程管理和增强安全性等方面发挥着重要作用,是我们开发人员和系统管理员不可或缺的工具.今天大姚给大家推荐一款非常好用的在线 SSH 管理工具:Xterminal. ...
 - 一镜到底,通过Llama大模型架构图看透transformers原理
			
一镜到底,通过Llama大模型架构图看透transformers原理 Llama Nuts and Bolts是Github上使用Go语言从零重写Llama3.1 8B-Instruct模型推理过程( ...