pip是Python包管理工具,该工具提供了对Python包的管理功能

基本
查看pip版本
升级pip版本
1 2 3
| pip install --upgrade pip
pip install -U pip
|

查看pip帮助信息
包管理
查看已安装包列表
1 2 3 4 5 6 7 8 9 10
| pip list
pip list --outdated pip list -o
pip list --uptodate pip list -u
|
安装包
1 2 3 4
| pip install [包名]
pip install numpy
|
事实上,还可以指定版本要求,允许使用的有:
- == :等于指定版本
- > :大于指定版本
- >= :大于等于指定版本
- < :小于指定版本
- <= :小于等于指定版本
1 2 3 4 5 6 7 8 9
| pip install "[包名]=[<版本]"
pip install "numpy==1.25.1"
pip install "[包名]>[版本]"
pip install "numpy>1.25.1"
|
升级包
1 2 3 4 5 6
| pip install --upgrade [包名] pip install -U [包名]
pip install -U numpy
|
同理,升级包时也可以使用==、>、>=、<、<=来指定版本要求。例如
1 2
| pip install "numpy<=1.24.2"
|

查看指定已安装包的信息
1 2 3 4 5 6 7 8 9 10 11
| pip show [包名]
pip show -f [包名]
pip show aliyun-python-sdk-core
pip show -f aliyun-python-sdk-core
|

卸载包
1 2 3 4 5
| pip uninstall [包名]
pip uninstall numpy
|
常用选项
-i 选项
-i (或—index-url) 选项:用于指定镜像源地址。可以加快下载、更新包的速度。示例如下
1 2 3 4 5
| pip3 install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple
pip3 install -U numpy -i https://pypi.tuna.tsinghua.edu.cn/simple
|