基本功能
$ pip install SomePackage
[...]
Successfully installed SomePackage
$ pip show --files SomePackage
Name: SomePackage
Version: 1.0
Location: /my/env/lib/pythonx.x/site-packages
Files:
../somepackage/__init__.py
[...]
$ pip list --outdated
SomePackage (Current: 1.0 Latest: 2.0)
$ pip install --upgrade SomePackage
[...]
Found existing installation: SomePackage 1.0
Uninstalling SomePackage:
Successfully uninstalled SomePackage
Running setup.py install for SomePackage
Successfully installed SomePackage
$ pip uninstall SomePackage
Uninstalling SomePackage:
/my/env/lib/pythonx.x/site-packages/somepackage
Proceed (y/n)? y
Successfully uninstalled SomePackage
高级用法
$ pip search "query"
$ pip list
- 安装软件包的指定版本号
通过使用==, >=, <=, >, <来指定一个版本号
$ pip install SomePackage # latest version
$ pip install SomePackage==1.0.4 # specific version
$ pip install 'SomePackage>=1.0.4' # minimum version
- 根据依赖文件安装软件包
想象一个场景,创建一个虚拟环境,然后安装了一些依赖的软件包,开发出了应用 APP。这个时候,你需要部署到服务器,就可以使用 pip 导出依赖文件列表,然后在服务器上根据依赖文件列表,自动安装对应的软件包。很方便!
pip freeze > requirements.txt
pip install -r requirements.txt