使用virtualenv或buildout安装PIL的问题

Ale*_*nko 70 python pip buildout easy-install python-imaging-library

当我使用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
Run Code Online (Sandbox Code Playgroud)

我明白了,easy_install将PIL打包到Egg中,而PIP则没有.与buildbot相同,它使用鸡蛋.

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

Mar*_*ers 96

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

pip install --no-index -f http://dist.plone.org/thirdparty/ -U PIL
Run Code Online (Sandbox Code Playgroud)

通过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
Run Code Online (Sandbox Code Playgroud)

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

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

[versions]
PIL = 1.1.7
Run Code Online (Sandbox Code Playgroud)

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

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

  • [Pillow](http://pypi.python.org/pypi/Pillow/1.6)是PIL的一个分支,目的是修复包装,它似乎是一个替代品. (14认同)
  • @MartijnPieters六个月后,这一变化仍未发布,这是支持分支恕我直言的一个很好的理由.此外,Pillow基本上完成了与上面接受的答案相同的事情,而不必指定备用索引. (4认同)

acl*_*ark 79

使用枕头:"友好"的PIL叉 :-)它提供:

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

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

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

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


yuv*_*lio 8

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

sudo apt-get install python2.7-dev

之后,pip install pil工作了.


Tai*_*Tea 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仍然是一个"弄脏手"的环境......