PIL在虚拟环境中读取图像文件时显示“数据流损坏”

0 投票
1 回答
3647 浏览
提问于 2025-04-17 06:00

我的Python和PIL是通过MacPorts在Snow Leopard上安装的。

当我尝试在系统的Python中用PIL打开一张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

这里

有什么想法吗?

1 个回答

1

看起来这是个问题。

一般来说,人们不应该再使用PIL了。

可以试试Pillow,链接在这里:https://pypi.org/project/Pillow/

我敢打赌在虚拟环境中这个会很好用。

撰写回答