为什么我收到“AttributeError:模块‘image’没有属性‘Image’”?

Avi*_*jee 5 python getpixel

当我尝试执行下面的程序时:

import image
img = image.Image("LutherBellPic.jpg")

print(img.getWidth())
print(img.getHeight())

p = img.getPixel(45, 55)
print(p.getRed(), p.getGreen(), p.getBlue())
Run Code Online (Sandbox Code Playgroud)

我不断收到以下错误:

AttributeError: module 'image' has no attribute 'Image'
Run Code Online (Sandbox Code Playgroud)

And*_*ris 15

cImage您安装的是软件包,而不是image软件包。

\n

因此,您必须使用以下命令卸载错误的软件包:

\n
pip uninstall image\n
Run Code Online (Sandbox Code Playgroud)\n

并使用以下命令安装正确的版本:

\n
pip install cImage\n
Run Code Online (Sandbox Code Playgroud)\n

有关每个包的详细信息可以在Python 包索引存储库中找到。

\n

\xce\x99n 简介:

\n

image package:基于 Python 的 Web 框架的图像处理库Django

\n

cImage package:Python 的图像处理库。

\n