pip 是 Python 包管理工具,该工具提供了对Python 包的查找、下载、安装、卸载的功能。目前如果你在 python.org 下载最新版本的安装包,则是已经自带了该工具。Python 2.7.9 + 或 Python 3.4+ 以上版本都自带 pip 工具。
早先python版本未自带pip工具,需要手动安装。
[root@centos7 ~]# python -V
Python 2.7.5
[root@centos7 ~]# pip -V
-bash: pip: 未找到命令
安装步骤如下:
[root@centos7 ~]# curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1863k 100 1863k 0 0 516k 0 0:00:03 0:00:03 --:–:-- 516k
[root@centos7 ~]# ll
总用量 1868
-rw-------. 1 root root 1420 5月 8 00:12 anaconda-ks.cfg
-rw-r–r--. 1 root root 1908226 5月 18 17:31 get-pip.py
[root@centos7 ~]# python get-pip.py
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Collecting pip<21.0
Downloading pip-20.3.4-py2.py3-none-any.whl (1.5 MB)
|████████████████████████████████| 1.5 MB 222 kB/s
Collecting setuptools<45
Downloading setuptools-44.1.1-py2.py3-none-any.whl (583 kB)
|████████████████████████████████| 583 kB 3.1 MB/s
Collecting wheel
Downloading wheel-0.36.2-py2.py3-none-any.whl (35 kB)
Installing collected packages: pip, setuptools, wheel
Successfully installed pip-20.3.4 setuptools-44.1.1 wheel-0.36.2
检查安装的pip命令版本
[root@centos7 ~]# pip -V
pip 20.3.4 from /usr/lib/python2.7/site-packages/pip (python 2.7)
(website) [sun@sun-site anaconda3]$ pip -V
pip 21.0.1 from /home/sun/anaconda3/envs/website/lib/python3.9/site-packages/pip (python 3.9)
(website) [sun@sun-site anaconda3]$ pip -V
pip 21.0.1 from /home/sun/anaconda3/envs/website/lib/python3.9/site-packages/pip (python 3.9)
(website) [sun@sun-site anaconda3]$ pip --helpUsage:
pip <command> [options]Commands:
install Install packages.
download Download packages.
(website) [sun@sun-site anaconda3]$ pip install flask
Collecting flask
Downloading Flask-2.0.0-py3-none-any.whl (93 kB)
…
Installing collected packages: MarkupSafe, Werkzeug, Jinja2, itsdangerous, click, flask
Successfully installed Jinja2-3.0.1 MarkupSafe-2.0.1 Werkzeug-2.0.1 click-8.0.0 flask-2.0.0 itsdangerous-2.0.1
(website) [sun@sun-site anaconda3]$ pip install django==3.2.1
…
Installing collected packages: django
Attempting uninstall: django
Found existing installation: Django 3.2.3
Uninstalling Django-3.2.3:
Successfully uninstalled Django-3.2.3
Successfully installed django-3.2.1
(website) [sun@sun-site anaconda3]$ pip install --upgrade django
Requirement already satisfied: django in
…
Attempting uninstall: django
Found existing installation: Django 3.2.1
Uninstalling Django-3.2.1:
Successfully uninstalled Django-3.2.1
Successfully installed django-3.2.3
(website) [sun@sun-site anaconda3]$ pip uninstall flask
Found existing installation: Flask 2.0.0
Uninstalling Flask-2.0.0:
Would remove:
/home/sun/anaconda3/envs/website/bin/flask
/home/sun/anaconda3/envs/website/lib/python3.9/site-packages/Flask-2.0.0.dist-info/*
/home/sun/anaconda3/envs/website/lib/python3.9/site-packages/flask/*
Proceed (y/n)? y
Successfully uninstalled Flask-2.0.0
(website) [sun@sun-site anaconda3]$ pip install -U pip
Requirement already satisfied: pip in ./envs/website/lib/python3.9/site-packages (21.0.1)
Collecting pip
Downloading pip-21.1.1-py3-none-any.whl (1.5 MB)
|████████████████████████████████| 1.5 MB 591 kB/s
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 21.0.1
Uninstalling pip-21.0.1:
Successfully uninstalled pip-21.0.1
Successfully installed pip-21.1.1
(website) [sun@sun-site anaconda3]$ pip list -o
Package Version Latest Type
---------- ------------------- ------ -----
setuptools 52.0.0.post20210125 56.2.0 wheel
(website) [sun@sun-site anaconda3]$ pip show django
Name: Django
Version: 3.2.3
Summary: A high-level Python Web framework that encourages rapid development and clean, pragmatic design.
Home-page: https://www.djangoproject.com/
Author: Django Software Foundation
Author-email: foundation@djangoproject.com
License: BSD-3-Clause
Location: /home/sun/anaconda3/envs/website/lib/python3.9/site-packages
Requires: sqlparse, asgiref, pytz
Required-by:
如果需要更详细信息使用pip show -f
(website) [sun@sun-site anaconda3]$ pip list
Package Version
------------ -------------------
asgiref 3.3.4
certifi 2020.12.5
click 8.0.0
Django 3.2.3
itsdangerous 2.0.1
Jinja2 3.0.1
MarkupSafe 2.0.1
pip 21.1.1
pytz 2021.1
setuptools 52.0.0.post20210125
sqlparse 0.4.1
Werkzeug 2.0.1
wheel 0.36.2
用法:pip [options]
命令 | 命令说明 |
---|---|
install | 安装软件包 |
download | 下载软件包 |
uninstall | 卸载软件包 |
freeze | 按着一定格式输出已安装包列表 |
list | 列出已安装的软件包 |
show | 显示有关已安装程序包的信息 |
check | 检查并验证已安装的软件包是否具有兼容的依赖项 |
config | 管理本地和全局配置 |
search | 在PyPI中搜索包 |
cache | 缓存检查和管理pip的wheel缓存 |
wheel | 根据您的要求创建.whl文件 |
hash | 散列计算包存档的散列 |
completion | 用于命令完成的助手命令 |
debug | 调试显示对调试有用的信息 |
help | 显示命令帮助 |
参数 | 参数说明 |
---|---|
-h, --help | 显示帮助 |
–isolated | 在隔离模式下独立运行pip,忽略环境变量和用户配置 |
-v, --verbose | 提供更多输出 |
-V, --version | 显示版本 |
-q, --quiet | 提供更多输出 |
–log <path> | 详细附加日志的路径 |
–no-input | 禁用输入提示 |
–proxy <proxy> | 在表单中指定代理[user:passwd@]代理 |
–retries <retries> | 每个连接应尝试的最大重试次数 (默认5次). |
–timeout <sec> | 设置套接字超时(默认为15秒) |
–exists-action <action> | 路径已存在时的默认操作:(s)witch,(i)gnore,(w)ipe,(b)ackup,(a)bort。 |
–trusted-host <hostname> | 标记此主机或host:port pair 作为受信任的,即使它没有有效的或任何HTTPS。 |
–cert <path> | 到备用CA包的路径。 |
–client-cert <path> | SSL客户端证书的路径,一个包含私钥和PEM格式证书的文件。 |
–cache-dir <dir> | 将缓存数据存储在
|
–no-cache-dir | 禁用缓存 |
–disable-pip-version-check | 禁用pip版本检查 |
–no-color | 抑制彩色输出 |
–no-python-version-warning | 对即将到来的不受支持的python关闭警告 |
–use-feature <feature> | 启用可能向后不兼容的新功能 |
–use-deprecated <feature> | 启用弃用的功能,这些功能将在将来被删除 |