首页 > 解决方案 > 使用'from PIL import Image'分配图像变量时'TypeError:'module'对象不可调用'

问题描述

我只是在尝试调整图像大小时收到此错误(在此处学习 Python)。运行 Windows 10。bride.jpg 保存在与我的脚本相同的目录中。

Traceback (most recent call last):
  File "C:\Users\Elliot\Python\scripts\c6\image_rotate.py", line 2, in <module>
    im = Image("bride.jpg")
TypeError: 'module' object is not callable

这是我的代码。这个确切的代码块在我导师的机器上运行得很好,我不知道为什么它不适合我。他正在运行 Ubuntu。这可能是原因吗?我已经在我的机器上安装了 PIL。如果有人可以解释我不理解的内容以及如何修复代码,我将不胜感激!

from PIL import Image
im = Image("bride.jpg")
new_im = im.resize((480,360))
new_im.save("bride.jpg")

标签: pythonpython-imaging-library

解决方案


应该是Image.open('bride.jpg'),不是Image('bride.jpg')


推荐阅读