使用virtualenv或buildout安装PIL的问题

时间:2010-03-21 00:19:08

标签: python python-imaging-library easy-install buildout pip

当我使用easy_install或buildout安装PIL时,它会以这种方式安装,我必须执行'import Image',而不是'来自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 个答案:

答案 0 :(得分:96)

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

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

pip install--no-index一起使用,可以避免冒险找到PIL的PyPI(非固定)原件。如果您要使用easy_install,则必须使用指向更正版本的源tarball的直接链接; easy_install固执地仍然使用查找链接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's development tree,因此这种解决方法可能很快就会过时。

编辑2013年2月:只需使用Pillow即可完成。 :-)显然等待修复原始包裹还没有得到回报。

答案 1 :(得分:79)

使用Pillow: the "friendly" PIL fork :-)它提供:

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

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

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

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

答案 2 :(得分:8)

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

sudo apt-get install python2.7-dev

之后,pip install pil工作了。

答案 3 :(得分:6)

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

通过执行.exe来在您的全局python site-packages中安装PIL: http://www.pythonware.com/products/pil/

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