为什么使用 pip 而不是 easy_install? [英] Why use pip over easy_install?
问题描述
一条 推特 写道:
不要使用easy_install,除非你就像刺伤自己的脸.使用点子.
Don't use easy_install, unless you like stabbing yourself in the face. Use pip.
为什么使用 pip 而不是 easy_install?是否主要是 PyPI 和包作者的错误?如果作者将垃圾源 tarball(例如:丢失的文件,没有 setup.py)上传到 PyPI,那么 pip 和 easy_install 都会失败.除了外观上的差异之外,为什么 Python 人(如上面的推文中所示)似乎强烈喜欢 pip 而不是 easy_install?
Why use pip over easy_install? Doesn't the fault lie with PyPI and package authors mostly? If an author uploads crap source tarball (eg: missing files, no setup.py) to PyPI, then both pip and easy_install will fail. Other than cosmetic differences, why do Python people (like in the above tweet) seem to strongly favor pip over easy_install?
(假设我们谈论的是 Distribute 包中的 easy_install,由社区维护)
(Let's assume that we're talking about easy_install from the Distribute package, that is maintained by the community)
推荐答案
这里的许多答案在 2015 年已经过时(尽管 丹尼尔罗斯曼最初接受的一个不是).以下是目前的状况:
Many of the answers here are out of date for 2015 (although the initially accepted one from Daniel Roseman is not). Here's the current state of things:
- 二进制包现在以轮子的形式分发(
.whl
文件)——不仅在 PyPI 上,而且在 Christoph Gohlke 的 Windows 扩展包.pip
可以处理轮子;easy_install
不能. - 虚拟环境(内置于 3.4,或者可以通过 添加到 2.6+/3.1+
virtualenv
) 已成为一个非常重要和突出的工具(并在 官方文档);它们包括开箱即用的pip
,但甚至不能与easy_install
一起正常工作. - 不再维护包含
easy_install
的distribute
包.它对setuptools
的改进被合并回setuptools
.尝试安装distribute
只会安装setuptools
. easy_install
本身只是准维护的.- 过去
pip
不如easy_install
的所有情况——从解压的源代码树、从 DVCS 存储库等安装——都早已不复存在;你可以pip install .
,pip install git+https://
. pip
随附来自 python.org 的官方 Python 2.7 和 3.4+ 包,如果您从源代码构建,则默认包含pip
引导程序.- 有关安装、使用和构建软件包的各种不完整文档已被 Python 打包用户指南一>.Python 自己关于 安装 Python 模块 的文档现在遵循本用户指南,并明确调用将
pip
作为首选安装程序". - 多年来,
pip
中还添加了其他新功能,而这些新功能在easy_install
中是永远不会出现的.例如,pip
通过构建需求文件,然后在每一侧使用单个命令安装它,可以轻松克隆站点包.或者将您的需求文件转换为本地存储库以用于内部开发.等等.
- Binary packages are now distributed as wheels (
.whl
files)—not just on PyPI, but in third-party repositories like Christoph Gohlke's Extension Packages for Windows.pip
can handle wheels;easy_install
cannot. - Virtual environments (which come built-in with 3.4, or can be added to 2.6+/3.1+ with
virtualenv
) have become a very important and prominent tool (and recommended in the official docs); they includepip
out of the box, but don't even work properly witheasy_install
. - The
distribute
package that includedeasy_install
is no longer maintained. Its improvements oversetuptools
got merged back intosetuptools
. Trying to installdistribute
will just installsetuptools
instead. easy_install
itself is only quasi-maintained.- All of the cases where
pip
used to be inferior toeasy_install
—installing from an unpacked source tree, from a DVCS repo, etc.—are long-gone; you canpip install .
,pip install git+https://
. pip
comes with the official Python 2.7 and 3.4+ packages from python.org, and apip
bootstrap is included by default if you build from source.- The various incomplete bits of documentation on installing, using, and building packages have been replaced by the Python Packaging User Guide. Python's own documentation on Installing Python Modules now defers to this user guide, and explicitly calls out
pip
as "the preferred installer program". - Other new features have been added to
pip
over the years that will never be ineasy_install
. For example,pip
makes it easy to clone your site-packages by building a requirements file and then installing it with a single command on each side. Or to convert your requirements file to a local repo to use for in-house development. And so on.
我知道在 2015 年使用 easy_install
的唯一一个很好的理由是在 OS X 10.5-10.8 中使用 Apple 预装的 Python 版本的特殊情况.从 10.5 开始,Apple 包含了 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
.
The only good reason that I know of to use easy_install
in 2015 is the special case of using Apple's pre-installed Python versions with OS X 10.5-10.8. Since 10.5, Apple has included easy_install
, but as of 10.10 they still don't include pip
. With 10.9+, you should still just use get-pip.py
, but for 10.5-10.8, this has some problems, so it's easier to sudo easy_install pip
. (In general, easy_install pip
is a bad idea; it's only for OS X 10.5-10.8 that you want to do this.) Also, 10.5-10.8 include readline
in a way that easy_install
knows how to kludge around but pip
doesn't, so you also want to sudo easy_install readline
if you want to upgrade that.
这篇关于为什么使用 pip 而不是 easy_install?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!