python - 使用'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")
解决方案
应该是Image.open('bride.jpg')
,不是Image('bride.jpg')
。
推荐阅读
- python - 如何在 python 中合并两个具有相同键键值的字典,以便我从任一字典中获得一个具有两个值列表的键?
- c# - 自 WebView 更改以来,xamarin 中的动态大小的 Web 视图
- c - 为允许更改存储的数据类型的队列创建通用结构
- r - 在 R 中绘图:仅删除特定位置的刻度线
- javascript - 在 React Native 中导入动态图像时,这些文件都不存在
- cpanel - 我在显示 "-":11:bad 命令的 cron 作业中有一些错误
- php - Codecept 没有显示任何 php 单元测试结果
- c# - Unity - 添加 Buffs 并将其分配给 UI,重复 for 循环进行分配
- javascript - 如何在反应中从父组件内部初始化子组件状态?
- typescript - 打字稿:从对象的联合中提取类型