为什么使用pip而不是easy_install?

2024-04-20 09:58:25 发布

您现在位置:Python中文网/ 问答频道 /正文

Atweet读取:

Don't use easy_install, unless you like stabbing yourself in the face. Use pip.

为什么使用pip而不是easy_install?是不是fault lie with PyPI and package authors mostly?如果作者将垃圾源tarball(例如:缺少文件,没有setup.py)上传到PyPI,那么pip和easy_安装都将失败。除了表面上的差异,为什么Python用户(如上面的tweet)似乎更喜欢pip而不是easy_install?

(假设我们讨论的是来自社区维护的分发包的easy_install)


Tags: installpiptheinpypiyouuseeasy
3条回答

这里的许多答案在2015年已经过时(尽管the initially accepted one from Daniel Roseman不是)。以下是当前情况:

  • 二进制包现在作为轮子(.whl文件)分发——不仅在PyPI上,而且在第三方存储库(如Christoph Gohlke's Extension Packages for Windows)中。pip可以处理轮子;easy_install不能。
  • 虚拟环境(内置于3.4中,或者可以通过^{}添加到2.6+/3.1+)已经成为一个非常重要和突出的工具(并在the official docs中推荐);它们包括pip开箱即用,但甚至不能与easy_install正常工作。
  • 已不再维护包含easy_installdistribute包。它对setuptools的改进被合并回setuptools。尝试安装distribute将只安装setuptools
  • easy_install本身只是准维护的。
  • 以前pip不如easy_install的所有情况(从未打包的源代码树安装、从DVCS repo安装等)早已不复存在;您可以pip install .pip install git+https://
  • pip附带来自Python.org的官方Python 2.7和3.4+包,如果从源代码构建,默认情况下会包含一个pip引导。
  • 关于安装、使用和构建包的各种不完整的文档已被Python Packaging User Guide替换。Python自己关于Installing Python Modules的文档现在遵循本用户指南,并显式地调用pip作为“首选安装程序”。
  • 在过去的几年中,pip还添加了一些新功能,这些功能将永远不会出现在easy_install中。例如,pip通过构建一个需求文件,然后在每一侧使用一个命令安装它,可以很容易地克隆站点包。或者将需求文件转换为本地repo以用于内部开发。等等。

据我所知,在2015年使用easy_install的唯一好理由是,在OS X 10.5-10.8中使用苹果预装的Python版本是一个特例。从10.5开始,苹果已经加入了easy_install,但是到10.10为止,他们仍然没有加入pip。对于10.9+,您仍然应该只使用get-pip.py,但是对于10.5-10.8,这有一些问题,因此更容易sudo easy_install pip。(一般来说,easy_install pip是一个坏主意;这只适用于OS X 10.5-10.8,您需要这样做。)另外,10.5-10.8包含readline,其方式是easy_install知道如何四处游荡,但pip不知道,因此如果您想升级,还需要sudo easy_install readline

另一个尚未提及的支持pip的原因是因为它是新的热点,并将在未来继续使用。

下面来自The Hitchhiker's Guide to Packaging v1.0Current State of Packaging部分的信息图显示,setuptools/easy_安装将在将来消失。

enter image description here

这里是distribute's documentation的另一个信息图,显示Setuptools和easy_install将被新的hotness-distributepip取代。虽然pip仍然是新的热点,但Distribute在2013年与Setuptools合并,发布了Setuptoolsv0.7。

enter image description here

来自伊恩·比金自己的introduction to pip

pip was originally written to improve on easy_install in the following ways

  • 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.

相关问题 更多 >