Hugo
Hugo

Reputation: 1688

How can I load an image on Python Pillow?

Helllo

I am using command line to get introduced to Pillow.

from PIL import Image
myImage = Image.open(green_leaves.jpg)

gives me the following error

name 'green_leaves' is not defined

Could you help me?

Thank you

Hugo

Upvotes: 0

Views: 345

Answers (2)

jonrsharpe
jonrsharpe

Reputation: 121966

The filename argument is a string, and should be in quotes:

myImage = Image.open("green_leaves.jpg")

Without the quotes, Python looks for the attribute jpg of the object referenced by name green_leaves, which does not exist; hence the NameError.

Upvotes: 2

Maxime Lorant
Maxime Lorant

Reputation: 36151

You need to put the file name between quotes, to be parsed as a string:

myImage = Image.open("green_leaves.jpg")

Your code attempts to access to a variable green_leaves (before acceding to its attribute jpg) which doesn't exist...

Upvotes: 1

Related Questions