使用virtualenv或buildou安装PIL的问题

2024-04-29 06:00:17 发布

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

当我使用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

我明白了,那个很容易安装的包PIL到鸡蛋里,而PIP没有。和buildbot一样,它使用鸡蛋。

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


Tags: installfromtestimageimportbinpilvirtualenv
3条回答

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

sudo apt-get install python2.7-dev

之后,pip install pil开始工作。

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

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

如果皮尔做了枕头做的事,叉子就会死。在那之前,我们有枕头。

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

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

pypi(作者)上打包的PIL版本与setuptools不兼容,因此不易安装。人们已经在别处创建了易于安装的版本。目前,您需要指定一个查找链接URL并使用^{}获取一个好的包:

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,请指定具有相同版本pin的egg或使用versions部分:

[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即可。:-)显然,等待原包装修好还没有收到效果。

相关问题 更多 >