im = Image.open('screenshot.png') NameError: name 'Image' is not defined
时间: 2023-08-09 07:09:56 浏览: 139
这个错误通常是因为没有正确导入Pillow库中的Image模块导致的。你需要在代码中添加以下导入语句:
```python
from PIL import Image
```
这样就可以正确地使用`Image.open()`函数来打开图片文件了。完整的代码如下:
```python
from PIL import Image
# 读取截图
im = Image.open('screenshot.png')
im.show()
```
记得在运行代码之前先安装Pillow库。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044736.png)
![png](https://img-home.csdnimg.cn/images/20210720083516.png)
![png](https://img-home.csdnimg.cn/images/20210720083516.png)
![png](https://img-home.csdnimg.cn/images/20210720083516.png)
![png](https://img-home.csdnimg.cn/images/20210720083516.png)
![png](https://img-home.csdnimg.cn/images/20210720083516.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://img-home.csdnimg.cn/images/20250102104920.png)
![png](https://img-home.csdnimg.cn/images/20210720083516.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![png](https://img-home.csdnimg.cn/images/20210720083516.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![crx](https://img-home.csdnimg.cn/images/20250102104920.png)