Ask coding questions

← Back to all posts
I get an AttributeError when I try to create a new image in PIL
Dunce (45)

I get the error:
AttributeError: type object 'Image' has no attribute 'new'

When I run the code:

from PIL import Image
image = Image.new("RGB", (100, 100))
Comments
hotnewtop
SixBeeps (5056)

Instead of

from PIL import Image

try

import PIL.Image

then use

image = PIL.Image.new("RGB", (100, 100))
Dunce (45)

@SixBeeps I get the same error.

Dunce (45)

@SixBeeps I just ran another repl with that code. I guess it had to do with something that come before the code snippet I showed, becouse it worked.

Dunce (45)

@SixBeeps I don't know what happened, I got it working now.