- 安装 指定第三方包
$ pip install 包名
# 例如:
$ pip install requests
- 安装 指定第三方包,并 指定版本号
$ pip install 包名==3.11.0
# 例如:
$ pip install requests==3.11.0
- 卸载 指定第三方包
$ pip uninstall 包名
# 例如:
$ pip uninstall requests
- 查看 已安装的第三方包
# 显示已安装的包
$ pip list
# 显示已安装的包,并列出版本信息
$ pip freeze
- 设置下载超时时间(安装过程中下载速度太慢,出现 read timed out 错误的情况使用)
$ pip --default-timeout=100 install requests
- 升级 pip
$ python -m pip install --upgrade pip
- 其他常用命令
# 显示版本和路径
$ pip --version
# 获取帮助
$ pip --help
# 升级pip
$ pip install -U pip
# 最新版本
$ pip install SomePackage
# 指定版本
$ pip install SomePackage==1.0.4
# 最小版本
$ pip install SomePackage>=1.0.4
# 升级包,通过使用==,>=, <=, >, < 来指定一个版本号
$ pip install --upgrade SomePackage # 或 pip install -U SomePackage
# 卸载包
$ pip uninstall SomePackage
# 搜索包(官方暂停使用:https://www.learnhard.cn/articles/926.html)
$ pip search SomePackage
# 显示安装包的信息
$ pip show
# 查看指定包的详细信息
$ pip show -f SomePackage
# 列出已安装的包
$ pip list
# 查看可升级的包
pip list -o
# 查看已经安装的包以及版本信息
$ pip freeze
# 安装包时指定安装路径
$ pip install SomePackage -i http://pypi.intra.xxx.com/simple/ --trusted-host pypi.intra.xxx.com
# 安装指定文件中的包
$ pip install -r requirements.txt