70

当我使用 easy_install 或 buildout 安装 PIL 时,它会以这样的方式安装,我必须执行“import Image”,而不是“from PIL import Image”。

但是,如果我执行“apt-get install python-imaging”或使用“pip -E test_pil install PIL”,一切正常。

以下是我如何尝试使用 virtualenv 安装 PIL 的示例:

# virtualenv --no-site-packages test_pil
# test_pil/bin/easy_install PIL
# test_pil/bin/python
Python 2.5.1 (r251:54863, Feb  6 2009, 19:02:12) 
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import PIL
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named PIL

我明白了,easy_install 将 PIL 打包到 Egg 中,而 PIP 没有。buildbot 也一样,它使用鸡蛋。

如何使用 easy_install 或 buildout 正确安装 PIL?

4

4 回答 4

96

pypi 上打包的 PIL 版本(作者)与 setuptools 不兼容,因此不是 easy_installable。人们已经在其他地方创建了 easy_installable 版本。目前,您需要指定一个查找链接 URL 并使用pip获取一个好的包:

pip install --no-index -f http://dist.plone.org/thirdparty/ -U PIL

通过pip install与您一起使用,--no-index您可以避免寻找 PIL 的 PyPI(非固定)原件的风险。如果要使用easy_install,则必须使用指向更正版本源 tarball 的直接链接;easy_install 仍然顽固地在 find-links URL 上使用 PyPI 链接:

easy_install http://dist.plone.org/thirdparty/PIL-1.1.7.tar.gz

要在构建中包含 PIL,请使用相同的版本引脚指定 egg 或使用版本部分:

[buildout]
parts =
find-links =
    http://dist.plone.org/thirdparty/
eggs =
    PIL
versions = versions

[versions]
PIL = 1.1.7

2011 年 3 月编辑:解决打包问题的修复程序现已合并到PIL 的开发树中,因此此解决方法可能很快就会过时。

2013 年 2 月编辑:只需使用Pillow 即可。:-) 很明显,等待原包装修复还没有得到回报。

于 2010-03-21T08:22:30.717 回答
79

使用Pillow:“友好”的 PIL 前叉:-) 它提供:

  • 完整的 setuptools 兼容性
  • 更快的发布周期
  • 没有与 PIL 不同的图像代码更改(即,它旨在跟踪所有 PIL 图像代码更改,并且在不向上游报告的情况下不进行任何更改。)
  • Windows 二进制文件

如果 PIL 完全按照 Pillow 所做的那样做,那么叉子就会死掉。在此之前,我们有 Pillow。

免责声明:我是 fork 作者,创建 Pillow 主要是为了让我的工作更轻松(尽管很高兴看到其他人也使用它)。

编辑:Pillow 2.0.0 于 2013 年 3 月 15 日发布。它提供 Python 3 支持和许多错误修复/增强。虽然我们仍在尝试跟踪上游 PIL 的变化,(不幸或幸运取决于你如何看待它)Pillow 已经开始偏离 PIL。

于 2011-10-14T16:19:14.000 回答
8

对于 Ubuntu,我发现我需要为我的 python 版本(2.7)安装 C 头文件包

sudo apt-get install python2.7-dev

后来,pip install pil工作了。

于 2013-02-14T18:45:03.893 回答
6

在 Windows 上,我在 virtualenv 中安装了 PIL,如下所示:

通过执行以下位置的 .exe 在您的全局 python 站点包中安装 PIL:http: //www.pythonware.com/products/pil/

然后,作为“自己动手”,将 C:\Python25\Lib\site-packages 中的 PIL.pth 文件和 PIL 目录复制到您的 virtualenv site-packages 目录。是的,python 仍然是一个“弄脏你的手”的环境......

于 2012-11-30T10:03:55.293 回答