【转载】Python包管理工具pip与easy_install

     初学 Python,总是提示缺少各种各样的 Python 包,于是了解了下 Python 的包安装管理工具:

1.setuptools 中的 easy_install (Download, build, install, upgrade, and uninstall Python packages -- easily!)

easy_install 是 setuptools 包里的一个命令,所以想使用 easy_install 就得安装 setuptools 。

①可以直接下载setuptools-0.6c11.win32-py2.7.exe文件安装

下载地址:http://pypi.python.org/pypi/setuptools

      安装完成之后在 Python 安装目录下的 Scripts 目录下就会有 easy_install.exe,将 Scripts 加到Path 变量里,就可以使用它来安装 Python 包了,只需要将包名作为参数,它就会自动到 Pypi 里去查找并安装,例如:

easy_install SQLObject

②通过下载 ez_setup.py 脚本安装 setuptools

脚本下载地址:http://peak.telecommunity.com/dist/ez_setup.py

      安装效果应该是和方法①是一样的(但是这里下载的是setuptools-0.6c11-py2.7.egg),不过根据官网的文档,对于 64 位的机器,只能使用第二种方式进行安装。

2.pip(a tool for installing and managing Python packages, a replacement for easy_install)

      pip 的安装需要 setuptools 或者 distribute 如果你使用的是 Python3.x 那么就只能使用distribute 因为 Python3.x 不支持 setuptools 。

可以通过脚本 get-pip.py 来安装 pip,脚本下载地址:

https://raw.github.com/pypa/pip/master/contrib/get-pip.py 

下载后执行即可安装 pip 。

      安装完成之后相关的命令程序,同样会放到 Python 安装路径下的 Scripts 目录下,然后就可以用如下方式安装相关的包:

pip install SomePackage

 

      据说 pip 是 easy_install 的替代品,初学 Python,体会得不够深刻,期待后期补充,下面是 pip官网上对 pip 与 easy_install 进行的比较

pip is meant to improve on easy_install. Some of the improvements:

  • All packages are downloaded before installation. Partially-completed installation doesn’t occur as a result.
  • Care is taken to present useful output on the console.
  • The reasons for actions are kept track of. For instance, if a package is being installed, pip keeps track of why that package was required.
  • Error messages should be useful.
  • The code is relatively concise and cohesive, making it easier to use programmatically.
  • Packages don’t have to be installed as egg archives, they can be installed flat (while keeping the egg metadata).
  • Native support for other version control systems (Git, Mercurial and Bazaar)
  • Uninstallation of packages.
  • Simple to define fixed sets of requirements and reliably reproduce a set of packages.

pip doesn’t do everything that easy_install does. Specifically:

  • It cannot install from eggs. It only installs from source. (In the future it would be good if it could install binaries from Windows .exe or .msi – binary install on other platforms is not a priority.)
  • It is incompatible with some packages that extensively customize distutils or setuptools in their setup.py files.

pip is complementary with virtualenv, and it is encouraged that you use virtualenv to isolate your installation.


上一篇:阿里云容器服务网络性能测试


下一篇:阿里云容器服务测评