pip安装使用详解

凉白开 python26435,445186字数 2423阅读8分4秒阅读模式

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

1、pip下载安装

1.1 pip下载文章源自运维生存时间-https://www.ttlsa.com/python/how-to-install-and-use-pip-ttlsa/

# wget "https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz#md5=834b2904f92d46aaa333267fb1c922bb" --no-check-certificate

1.2 pip安装文章源自运维生存时间-https://www.ttlsa.com/python/how-to-install-and-use-pip-ttlsa/

# tar -xzvf pip-1.5.4.tar.gz
# cd pip-1.5.4
# python setup.py install

2. pip使用详解

2.1 pip安装包文章源自运维生存时间-https://www.ttlsa.com/python/how-to-install-and-use-pip-ttlsa/

# pip install SomePackage
  [...]
  Successfully installed SomePackage

2.2 pip查看已安装的包文章源自运维生存时间-https://www.ttlsa.com/python/how-to-install-and-use-pip-ttlsa/

# pip show --files SomePackage
  Name: SomePackage
  Version: 1.0
  Location: /my/env/lib/pythonx.x/site-packages
  Files:
   ../somepackage/__init__.py
   [...]

2.3 pip检查哪些包需要更新文章源自运维生存时间-https://www.ttlsa.com/python/how-to-install-and-use-pip-ttlsa/

# pip list --outdated
  SomePackage (Current: 1.0 Latest: 2.0)

2.4 pip升级包文章源自运维生存时间-https://www.ttlsa.com/python/how-to-install-and-use-pip-ttlsa/

# pip install --upgrade SomePackage
  [...]
  Found existing installation: SomePackage 1.0
  Uninstalling SomePackage:
    Successfully uninstalled SomePackage
  Running setup.py install for SomePackage
  Successfully installed SomePackage

2.5 pip卸载包文章源自运维生存时间-https://www.ttlsa.com/python/how-to-install-and-use-pip-ttlsa/

$ 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文章源自运维生存时间-https://www.ttlsa.com/python/how-to-install-and-use-pip-ttlsa/

# pip install redis

3.2 卸载redis文章源自运维生存时间-https://www.ttlsa.com/python/how-to-install-and-use-pip-ttlsa/

# 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 查看待更新包文章源自运维生存时间-https://www.ttlsa.com/python/how-to-install-and-use-pip-ttlsa/

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解决文章源自运维生存时间-https://www.ttlsa.com/python/how-to-install-and-use-pip-ttlsa/

5. 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 <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. 结束

安装使用一目了然,太简单了。文章源自运维生存时间-https://www.ttlsa.com/python/how-to-install-and-use-pip-ttlsa/ 文章源自运维生存时间-https://www.ttlsa.com/python/how-to-install-and-use-pip-ttlsa/

weinxin
我的微信
微信公众号
扫一扫关注运维生存时间公众号,获取最新技术文章~
凉白开
  • 本文由 发表于 22/04/2014 01:14:30
  • 转载请务必保留本文链接:https://www.ttlsa.com/python/how-to-install-and-use-pip-ttlsa/
评论  26  访客  19
    • 王超
      王超 1

      这个不错,可以试试去7995a161e9dbcc73a817ec78152bf2cc

      • 123
        123 1

        7995a161e9dbcc73a817ec78152bf2cc好的呀

        • 匿名
          匿名 9

          3df4f982afaaf46436f117232acfeaf6董事长黄飞鸿

          • tangweizhe863
            tangweizhe863 0

            你的终端为什么 帮助文档能显示中文呢?什么系统啊

            • 知乎网友
              知乎网友 0

              一劳永逸的方法是挂梯子,pip的源被墙了。我用的是天路加速器,他们官网的命令行加速教程写的比较清楚

                • 匿名
                  匿名 9

                  @ 知乎网友 阿里云镜像即可

                • 匿名
                  匿名 9

                  Could not find platform independent libraries
                  Could not find platform dependent libraries
                  Fatal Python error: Py_Initialize: Unable to get the locale encoding
                  这是怎么回事?遇到过这种情况么?

                  • 运维生存时间网友
                    运维生存时间网友 9

                    windows下的话:用CMD控制台进入该目录,然后输入python setup.py install;安装完后,再去配置环境变量(注:path下添加的是“自己的python安装路径\Scripts;”)

                    • Python
                      Python 9

                      下载后setup不是setup.exe,而是setup.py,这个在那里安装?怎么安装呢?

                        • 默北
                          默北 6

                          @ Python windows? python执行咯

                          • 匿名
                            匿名 9

                            @ Python windows下的话:用CMD控制台进入该目录,然后输入python setup.py install;安装完后,再去配置环境变量(注:path下添加的是“自己的python安装路径\Scripts;”)

                          • ddea
                            ddea 9

                            Thank you

                            • tack
                              tack 9

                              @ solvsky SomePackage ?不觉好笑么?

                              • retack
                                retack 9

                                @ tack 一点都不好笑

                                • lxw
                                  lxw 0

                                  @ tack 请问哪里好笑了? 你倒是挺好笑的!

                                  • 匿名
                                    匿名 9

                                    @ tack 蠢到极点

                                  评论已关闭!