方法在一个程序中有效,但在其他程序中无效

2024-04-26 18:51:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在编写一个问题的解决方案,我遇到了一个关于PIL图像方法的问题。你知道吗

choice = input("Would you like to save the maze as a file, Y/N?").upper()
if choice == "Y":
    canvas.update()
    canvas.postscript(file="maze.eps", colormode='color')
    img = Image.open("maze.eps")

但是,我收到以下错误消息:

Traceback (most recent call last):
  File "C:\Users\Matthew\Desktop\NEA\Technical Solution\mazeVisualiser.py", line 66, in <module>
    img = Image.open("maze.eps")
AttributeError: type object 'Image' has no attribute 'open'

但在学习PIL模块时,我知道这是有效的:

from PIL import Image

img = Image.open('brick-house.png')

任何帮助将不胜感激,因为这已使我完全陷入困境。你知道吗


Tags: 方法图像imageyouimginputpilopen