pip安装使用详解 – 21运维
通知: .-...

pip安装使用详解

python 21运维 5810浏览 0评论

pip类似RedHat里面的yum,安装Python包非常方便。本节详细介绍pip的安装、以及使用方法。

1、pip安装

yum install python-pip -y

yum安装报错No package python-pip available. 解决办法:多数新系统都可以正常安装,一般的服务器提供商都有提供安装好了的epel-release,这种场景一般出现于自己搭建的linux服务器或 虚拟机,解决办法:

yum install epel-release -y

再次安装,问题解决。
2. pip使用详解

# 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            覆盖的方式记录verbose错误日志,默认文件:/root/.pip/pip.log
  --log                 不覆盖记录verbose输出的日志.
  --proxy              Specify a proxy in the form [user:passwd@]proxy.server:port.
  --timeout              连接超时时间 (默认15秒).
  --exists-action     Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup.
  --cert                证书.

2.1 pip安装包

# 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

3. pip使用实例

3.1 安装redis

3.2 卸载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

3.3 查看待更新包

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)

转载请注明:21运维 » pip安装使用详解

发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址