Python的包管理工具Pip
2015-09-18 11:58
861 查看
Python的包管理工具Pip
pip 是一个安装和管理 Python 包的工具 , 是 easy_install 的一个替换品。本文将详细说明 安装 pip 的方法和 使用 pip 的一些基本操作如安装、更新和卸载 python 包。[b]distribute[/b]是setuptools的取代(Setuptools包后期不再维护了),[b]pip[/b]是easy_install的取代。
pip的安装需要setuptools 或者 distribute,如果你使用的是Python3.x那么就只能使用distribute因为Python3.x不支持setuptools。
这就简单的介绍一下Pip的安装与使用:
安装:
curl -O https://bootstrap.pypa.io/get-pip.py[/code]python get-pip.py
使用方法:pip install SomePackage pip search "query" pip install --upgrade SomePackage pip install --upgrade SomePackage==version
补充:
包安装后的py文件路径:/usr/local/lib/python2.7/dist-packagespip安装使用详解
pip类似RedHat里面的yum,安装Python包非常方便。本节详细介绍pip的安装、以及使用方法。
2.1 pip安装包
# pip install SomePackage
[...]
Successfully installed SomePackage
1 2 3 | # 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
[...]
1 2 3 4 5 6 7 | # 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)
1 2 | # 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
1 2 3 4 5 6 7 | # 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
1 2 3 4 5 | $ pip uninstall SomePackage Uninstalling SomePackage: /my/env/lib/pythonx.x/site-packages/somepackage Proceed (y/n)? y Successfully uninstalled SomePackage |
3. pip使用实例
3.1 安装redis# pip install redis
1 | # pip install redis |
# pip uninstall redis
Uninstalling redis:
/usr/lib/python2.6/site-packages/redis-2.9.1-py2.6.egg-info
.....省略一些内容....
Proceed (y/n)? y
Successfully uninstalled redis
1 2 3 4 5 6 | # pip uninstall redis Uninstalling redis: /usr/lib/python2.6/site-packages/redis-2.9.1-py2.6.egg-info .....省略一些内容.... Proceed (y/n)? y Successfully uninstalled redis |
pip list --outdate
pygpgme (Current: 0.1 Latest: 0.3)
pycurl (Current: 7.19.0 Latest: 7.19.3.1)
iniparse (Current: 0.3.1 Latest: 0.4)
1 2 3 4 | pip list --outdate pygpgme (Current: 0.1 Latest: 0.3) pycurl (Current: 7.19.0 Latest: 7.19.3.1) iniparse (Current: 0.3.1 Latest: 0.4) |
4. 常见错误
4.1 ImportError No module named setuptools请参考《ImportError No module named setuptools解决》
5. pip参数解释
# pip --helpUsage:
pip <command> [options]
Commands:
install 安装包.
uninstall 卸载包.
freeze 按着一定格式输出已安装包列表
list 列出已安装包.
show 显示包详细信息.
search 搜索包,类似yum里的search.
wheel Build wheels from your requirements.
zip 不推荐. Zip individual packages.
unzip 不推荐. Unzip individual packages.
bundle 不推荐. Create pybundles.
help 当前帮助.
General Options:
-h, --help 显示帮助.
-v, --verbose 更多的输出,最多可以使用3次
-V, --version 现实版本信息然后退出.
-q, --quiet 最少的输出.
--log-file <path> 覆盖的方式记录verbose错误日志,默认文件:/root/.pip/pip.log
--log <path> 不覆盖记录verbose输出的日志.
--proxy <proxy> Specify a proxy in the form [user:passwd@]proxy.server:port.
--timeout <sec> 连接超时时间 (默认15秒).
--exists-action <action> Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup.
--cert <path> 证书.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | # pip --help Usage: pip <command> [options] Commands: install 安装包. uninstall 卸载包. freeze 按着一定格式输出已安装包列表 list 列出已安装包. show 显示包详细信息. search 搜索包,类似yum里的search. wheel Build wheels from your requirements. zip 不推荐. Zip individual packages. unzip 不推荐. Unzip individual packages. bundle 不推荐. Create pybundles. help 当前帮助. General Options: -h, --help 显示帮助. -v, --verbose 更多的输出,最多可以使用3次 -V, --version 现实版本信息然后退出. -q, --quiet 最少的输出. --log-file <path> 覆盖的方式记录verbose错误日志,默认文件:/root/.pip/pip.log --log <path> 不覆盖记录verbose输出的日志. --proxy <proxy> Specify a proxy in the form [user:passwd@]proxy.server:port. --timeout <sec> 连接超时时间 (默认15秒). --exists-action <action> Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup. --cert <path> 证书. |
6. 结束
安装使用一目了然,太简单了。相关文章推荐
- Flask 中的路由与反向路由
- python Exception
- python处理字符串
- 转载:15个最受欢迎的Python开源框架
- Python: Ubuntu 安装numpy,scipy,matplotlib
- Python线程
- Python闭包与函数对象
- 趣味Python入门(一):初识Python
- 使用python进行文本分类
- 趣味Python入门(一):初识Python
- Python 中的 classmethod 和 staticmethod 有什么具体用途?
- Python2.7环境下安装pydbg
- Python快速入手
- python可变集合类型方法
- python集合类型方法
- 人们对Python在企业级开发中的10大误解
- 数值拟合
- python MySQLdb使用
- 10 个 Python IDE 和代码编辑器
- Python初学者的一些技巧