本文介绍了使用 virtualenv 或 buildout 安装 PIL 的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用 easy_install 或 buildout 安装 PIL 时,它以这种方式安装,我必须执行导入图像",而不是从 PIL 导入图像".

When I install PIL using easy_install or buildout it installs in such way, that I must do 'import Image', not 'from PIL import Image'.

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

However, if I do "apt-get install python-imaging" or use "pip -E test_pil install PIL", all work fine.

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

Here are examples of how I trying to install PIL using virtualenv:

# 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 相同,它使用鸡蛋.

I see, that easy_install pack PIL into the Egg, and PIP does not. Same thing with buildbot, it uses eggs.

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

How could I install PIL properly, using easy_install or buildout?

推荐答案

pypi(由作者)打包的 PIL 版本与 setuptools 不兼容,因此不容易安装.人们已经在别处创建了 easy_installable 版本.目前,您需要指定一个查找链接 URL 并使用 pip 得到一个好包裹:

The PIL version packaged on pypi (by the author) is incompatible with setuptools and thus not easy_installable. People have created easy_installable versions elsewhere. Currently, you need to specify a find-links URL and use pip get a good package:

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 链接:

By using pip install with the --no-index you avoid running the risk of finding the PyPI (non-fixed) original of PIL. If you were to use easy_install, you must use a direct link to the source tarball of a corrected version; easy_install stubbornly still uses the PyPI link over the find-links URL:

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

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

To include PIL in a buildout, either specify the egg with the same version pin or use a versions section:

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

[versions]
PIL = 1.1.7

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

Edit March 2011: Fixes to address the packaging issues have been merged into PIL's development tree now, so this workaround may soon be obsolete.

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

Edit February 2013: Just use Pillow and be done with it. :-) Clearly waiting for the original package to be fixed has not paid off.

这篇关于使用 virtualenv 或 buildout 安装 PIL 的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 04:20
查看更多