Skip to main content
 首页 » 编程设计

python之在 OS X 10.7 (Lion) 上使用 scipy 颜色和 imsave

2025年05月04日11exmyth

我试图在 OS X 10.7 上运行 imsave 和 imshow 以及处理数组中颜色的基本 scipy 功能,但无济于事。这是我的代码,然后我将发布我的错误。有什么方法可以永久修复或绕过这个问题,这样我就可以在我的 Mac 上使用这个功能了吗?我在运行 Ubuntu 的 Linux 机器上运行了这段相同的代码并取得了成功。

from numpy import * 
from scipy import * 
 
a = zeros((3,500,400)) 
 
a[1,0:100,0:200] = 255 
 
 
imsave('foo.png',a) 

如果这一切正常,我应该只得到一个 500x400 像素的黑框,并在左上角的 100x200 像素内得到一个绿色框。 但是我得到了这个错误

“回溯(最近调用最后): 文件“colorstuff.py”,第 10 行,位于 imsave('foo.png',a) NameError: 名称 'imsave' 未定义"

和 imshow 的类似错误。

关于如何避免此错误的任何想法?

(在旁注中,我尝试从 scipy.misc 导入并得到完全相同的错误)

请您参考如下方法:

来自 SciPy 手册:

Note that the Python Imaging Library (PIL) is not a dependency of SciPy and therefore the pilutil module is not available on systems that don’t have PIL installed.

您需要为 OSX 安装 PIL。我不确定它是否可用。