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/C++音视频开发64-共享解码线程/重复利用解码/极低CPU占用/画面同步/进度同步
一.前言 共享解码线程主要是为了降低CPU占用,重复利用解码,毕竟在一个监控系统中,很可能打开了同一个地址,需要在多个不同的窗口中播放,形成多屏渲染的效果,做到真正的完全的画面同步,在主解码线程中切换 ...
- Qt开发经验小技巧271-275
编程的过程中经常遇到需要将QString转成char *或者const char *的情况,在转换成QByteArray后调用.data()或者.constData()函数进行转换,这里需要注意的是, ...
- Web网页端IM产品RainbowChat-Web的v7.0版已发布
一.关于RainbowChat-Web RainbowChat-Web是一套Web网页端IM系统,是RainbowChat的姊妹系统(RainbowChat是一套基于开源IM聊天框架 MobileIM ...
- RAG实践 - AI 知识库问答功能的建设
最近在工作中构建了一套自动的基于文档中心为数据集构建知识库 AI 问答的系统,来提升用户体验和技术支持效率,分享一下在实现过程中的技术选型和架构设计. 背景 先说下背景,我们公司的产品 FinClip ...
- Mongodb 基础与安装
官网链接:https://docs.mongodb.com/ 参考链接:https://www.runoob.com/mongodb/mongodb-linux-install.html 1.什么是M ...
- ClickHouse-4SQL参考
SQL参考 ClickHouse支持以下形式的查询: SELECT INSERT INTO CREATE ALTER 其他类型的查询 ClickHouse SQL 语句 语句表示可以使用 SQL 查询 ...
- 推荐几个不错的 Linux 服务器管理工具
前言 选择一款好的 Linux 服务器管理工具能够极大地提高运维效率,保障业务连续性.今天大姚给大家分享3款不错的 Linux 服务器管理工具,希望可以帮助到有需要的同学. 1Panel 1Panel ...
- C :文件
一直没有系统学习过该章节,现参考<C语言程序设计 (第四版)谭浩强> C文件基本知识 什么是文件 文件名 文件的分类 文件缓冲区 文件类型指针 typedef struct { short ...
- Nibbles PG walkthrough Intermediate
nmap nmap -p- -A 192.168.239.47 Starting Nmap 7.95 ( https://nmap.org ) at 2025-01-15 02:26 UTC Nmap ...
- VS2022编译项目出现““csc.exe”已退出,代码为 -1073741819”的错误解决办法
1.问题描述 编译出错如下图所示: 2.解决办法 在NuGet包中输入Microsoft.Net.Compilers,安装该包,安装完后重新生成就不报错了,如下图所示: