【轉載】Python包管理工具pip與easy_install

      初學 Python,老是提示缺乏各類各樣的 Python 包,因而瞭解了下 Python 的包安裝管理工具: python

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

easy_install 是 setuptools 包裏的一個命令,因此想使用 easy_install 就得安裝 setuptools 。 github

①能夠直接下載setuptools-0.6c11.win32-py2.7.exe文件安裝 工具

下載地址:http://pypi.python.org/pypi/setuptools ui

      安裝完成以後在 Python 安裝目錄下的 Scripts 目錄下就會有 easy_install.exe,將 Scripts 加到Path 變量裏,就可使用它來安裝 Python 包了,只須要將包名做爲參數,它就會自動到 Pypi 裏去查找並安裝,例如: spa

easy_install SQLObject

②經過下載 ez_setup.py 腳本安裝 setuptools code

腳本下載地址:http://peak.telecommunity.com/dist/ez_setup.py orm

      安裝效果應該是和方法①是同樣的(可是這裏下載的是setuptools-0.6c11-py2.7.egg),不過根據官網的文檔,對於 64 位的機器,只能使用第二種方式進行安裝。 ip

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

      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.

相關文章
相關標籤/搜索