特点
- Python 官方推荐的包安装工具
- 从 PyPI 安装和管理 Python 包
- 支持 requirements.txt 批量安装
- 支持虚拟环境隔离依赖
- 与 Python 捆绑安装,开箱即用
安装
# 直接安装最新版
pip install [package]
# 安装指定版本
pip install requests==2.9.0
# 安装 >=2.9.0 版本
pip install requests>=2.9.0
# 安装 >=2.9.0, < 2.10.0 版本
pip install requests==2.9.*
# 安装 >=2.9.0, < 3.0.0 版本
pip install requests~=2.9.0 # 同上
# 指定源安装
pip install --index https://pypi.mirrors.ustc.edu.cn/simple/ [package]升级
# 升级包
pip install --upgrade [package]
配置文件
~/.pip/pip.conf卸载
pip uninstall [package]pip 自升级
python -m pip install --upgrade pippip 如果安装失败(没有使用管理员权限安装)
py -m ensurepip --upgradepip 查看版本
pip show pip
pip --versionpip 换源
设置代理
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
proxy = http://localhost:7890永久
在 C:\User\{User_name}\pip\pip.ini 下面复制
# 阿里源
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host = mirrors.aliyun.com
# 中科大源
[global]
index-url = https://pypi.mirrors.ustc.edu.cn/simple/
[install]
trusted-host = pypi.mirrors.ustc.edu.cn
# 清华大学源
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple/
[install]
trusted-host = mirrors.tsinghua.com
# 豆瓣源
[global]
index-url = http://pypi.douban.com/simple/
[install]
trusted-host = mirrors.douban.com临时
# 清华大学:https://pypi.tuna.tsinghua.edu.cn/simple
# 阿里云:http://mirrors.aliyun.com/pypi/simple/
# 豆瓣:http://pypi.douban.com/simple/
pip install -i [url] [package-name]手动安装本地包
python -m pip install "C:\Users\xxx\Downloads\d2l-1.0.0b0-py3-none-any.whl"pip 发布
pip install setuptools, wheel, twine