当我使用 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?
最佳答案
pypi(作者)上打包的 PIL 版本与 setuptools 不兼容,因此无法轻松安装。人们已经在其他地方创建了 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's development tree现在,所以这种解决方法可能很快就会过时。
2013 年 2 月编辑:只需使用 Pillow并完成它。 :-) 显然等待原包装修复没有得到返回。
关于python - 使用 virtualenv 或 buildout 安装 PIL 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2485295/