Pip是现代的、通用的Python包管理工具。提供了对Python 包的查找、下载、安装、卸载的功能。
安装包
>> pip install Django # 安装最新稳定的版本,可能会将某些依赖的版本更新为符合的版本。所以要可能的话,项目中版本号全部都限制好。
>> pip install Django==3.0 # 安装3.0版本
>> pip install Django>=3.0 # 安装3.0及以上的版本
>> pip install Django~=3.0 # 安装3.0小版本匹配即安装3.0.x中最新稳定的版本
>> pip install -e 本地目录
>> pip install -e git+https://github.com/django/django.git#egg=django
>> pip install -e git+ssh://[email protected]:django/django.git#egg=django
>> pip install -r requirements.txt
>> pip install -t 位置目录
下载包 把指定的包的二进制文件下载到指定位置
>> pip download django -d ${DEST}
删除包
>> pip uninstall Django
-r, --requirement <file> Use the order in the given requirements file and its comments when generating output. This option can be used multiple times.
-f, --find-links <url> URL for finding packages, which will be added to the output.
-l, --local If in a virtualenv that has global access, do not output globally-installed packages.
--user Only output packages installed in user-site.
--path <path> Restrict to the specified installation path for listing packages (can be used multiple times).
--all Do not skip these packages in the output: setuptools, pip, distribute, wheel
--exclude-editable Exclude editable package from output.
>> pip freeze
asgiref==3.2.10
Django==3.0.8
pytz==2020.1
sqlparse==0.3.1
Usage:
pip3 list [options]
Description:
List installed packages, including editables.
Packages are listed in a case-insensitive sorted order.
List Options:
-o, --outdated List outdated packages # 列出过期
-u, --uptodate List uptodate packages # 列出最新
-e, --editable List editable projects. # 列出可编辑
-l, --local If in a virtualenv that has global access, do not list globally-installed packages. # 列出安装在虚拟环境中的
--user Only output packages installed in user-site. # 安装在用户目录下的
--path <path> Restrict to the specified installation path for listing packages (can be used multiple times).
--pre Include pre-release and development versions. By default, pip only finds stable versions.
--format <list_format> Select the output format among: columns (default), freeze, or json
--not-required List packages that are not dependencies of installed packages.
--exclude-editable Exclude editable package from output.
--include-editable Include editable package from output.
展示指定的已安装的包
>> pip show Django
Name: Django
Version: 3.0.8
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: [email protected]
License: BSD
Location: /home/ling/env/lib/python3.8/site-packages
Requires: sqlparse, asgiref, pytz
Required-by:
检查某个包的依赖是否合适
>> pip check Django
launchpadlib 1.10.13 requires testresources, which is not installed.
flask-security-too 3.4.2 requires email-validator, which is not installed.
awscli 1.18.66 has requirement botocore==1.16.16, but you have botocore 1.16.6.
用来配置本地和全局的配置
>> pip config list --[user|global] # 列出用户|全局的设置
>> pip config get global.index-url # 得到这key对应的value
>> https://mirrors.aliyun.com/pypi/simple/
>> pip config set key value
>> pip config unset key
在pypi里搜索相关包
>> pip search flask
Flask-SimpleMDE (0.3.0) - Flask-SimpleMDE - a Flask extension for SimpleMDE
Flask-Pure (0.5) - Flask-Pure - a Flask extension for Pure.css
Flask-OrientDB (0.1) - A Flask extension for using OrientDB with Flask
Flask-ElasticUtils (0.1.7) - ElasticUtils for Flask
Flask-Waitress (0.0.1) - Flask Waitress
sockjs-flask (0.3) - SockJs for Flask
Flask-Stripe (0.1.0) - Flask-Stripe
Flask-PubSub (0.1.0) - Flask-PubSub
...
管理pip的本地缓存
>> pip cache dir
/home/stephen-ling/,cache/pip
>> pip cache info
Location: /home/stephen-ling/.cache/pip/wheels
Size: 0 bytes
Number of wheels: 0
打包成二进制文件
>> pip wheel Django
计算一个包的hash值
提供一些debug有用的信息, 不知道可以怎么用。
查询帮助
>> pip help