使用virtualenv或buildout安装PIL的问题
当我使用 easy_install 或 buildout 安装 PIL 时,它的安装方式是,我必须“导入图像”,而不是“从 PIL 导入图像”。
但是,如果我执行“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?
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'.
However, if I do "apt-get install python-imaging" or use "pip -E test_pil install PIL", all work fine.
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
I see, that easy_install pack PIL into the Egg, and PIP does not. Same thing with buildbot, it uses eggs.
How could I install PIL properly, using easy_install or buildout?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
pypi 上打包的 PIL 版本(作者)与 setuptools 不兼容,因此无法 easy_installable。人们在其他地方创建了 easy_installable 版本。目前,您需要指定 find-links URL 并使用
pip
获得一个好的包:通过将
pip install
与--no-index
一起使用,您可以避免找到 PIL 的 PyPI(非固定)原始版本的风险。如果您要使用easy_install
,则必须使用指向更正版本的源 tarball 的直接链接; easy_install 仍然顽固地使用 find-links URL 上的 PyPI 链接:要在构建中包含 PIL,请指定具有相同版本 pin 的 Egg 或使用版本部分:
2011 年 3 月编辑:解决打包问题的修复已合并到PIL 的开发树 现在,这个解决方法可能很快就会过时。
2013 年 2 月编辑:只需使用 Pillow 即可完成。 :-) 显然等待原始包被修复并没有得到回报。
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: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 useeasy_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:To include PIL in a buildout, either specify the egg with the same version pin or use a versions section:
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.
Edit February 2013: Just use Pillow and be done with it. :-) Clearly waiting for the original package to be fixed has not paid off.
使用 Pillow:“友好的”PIL 分支 :-) 它提供:
如果 PIL 完全按照 Pillow 所做的事情,那么 fork 将消亡。在那之前,我们还有 Pillow。
免责声明:我是 fork 作者,创建 Pillow 主要是为了让我的工作更轻松(尽管很高兴看到其他人也使用它)。
编辑:Pillow 2.0.0 于 2013 年 3 月 15 日发布。它提供 Python 3 支持和许多错误修复/增强。虽然我们仍在尝试跟踪上游 PIL 的变化,(不幸或幸运取决于你如何看待它)Pillow 已经开始偏离 PIL。
Use Pillow: the "friendly" PIL fork :-) It offers:
If PIL ever does exactly what Pillow does, then the fork will die. Until that happens, we have Pillow.
DISCLAIMER: I am the fork author, and Pillow was created mainly to make my job easier (although it's great to see other folks using it too).
EDIT: Pillow 2.0.0 was released on March 15, 2013. It offers Python 3 support and many bug fixes/enhancements. While we still attempt to track changes with upstream PIL, (unfortunately or fortunately depending on how you look at it) Pillow has begun to drift away from PIL.
对于 Ubuntu,我发现我需要为我的 python 版本 (2.7) 安装 C 头文件包
sudo apt-get install python2.7-dev
之后,
pip install pil
工作了。For Ubuntu I found I needed to to install the C headers package for my python version (2.7)
sudo apt-get install python2.7-dev
Afterwards,
pip install pil
worked.在 Windows 上,我在 virtualenv 中安装了 PIL,如下所示:
通过执行以下位置的 .exe 在全局 python 站点包中安装 PIL:
http://www.pythonware.com/products/pil/
然后,作为“do it myself-er”,将 C:\Python25\Lib\site-packages 中的 PIL.pth 文件和 PIL 目录复制到 virtualenv site-packages 目录。是的,Python 仍然是一个“亲自动手”的环境......
On Windows, I installed PIL in a virtualenv as follows:
Install PIL in your global python site-packages by executing the .exe from:
http://www.pythonware.com/products/pil/
Then, as a "do it yourself-er", copy the PIL.pth file and PIL directory in C:\Python25\Lib\site-packages to your virtualenv site-packages directory. Yeah, python is still a "get your hands dirty" environment...