【发布时间】:2011-11-09 23:51:22
【问题描述】:
我的 python 和 PIL 安装来自 Snow Leopard 上的 MacPorts。
当我尝试使用 PIL 在系统 python 中打开 JPG 图像时,我没有收到任何错误。
$ python
>>> import Image
>>> img = Image.open("test.jpg")
>>> img2 = img.resize((1,1))
>>> # no errors!!!
但是当我创建一个虚拟环境时
$ virtualenv --no-site-packages venv
$ cd venv/
$ source bin/activate
(venv) $ pip install PIL
...
(venv) $ python
>>> import Image
>>> img = Image.open("../test.jpg")
>>> img2 = img.resize((1,1))
...
IOError: broken data stream when reading image file
Here 是一个完整的转储,包括 PIL 的整个构建。
有什么想法吗?
【问题讨论】:
-
你从中得到什么 >>> from PIL import _imaging >>> _imaging
-
在 virtualenv 中:
<module 'PIL._imaging' from '/Users/miki725/Development/venv/lib/python2.7/site-packages/PIL/_imaging.so'>在系统中:<module 'PIL._imaging' from '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PIL/_imaging.so'> -
对我来说似乎可以使用 python 2.7 和 py27-virtualenv 1.6.1。你用的是什么版本?
标签: python macos python-imaging-library virtualenv