Bradley
Bradley

Reputation: 3

"Undefined variable from import" error when trying to use Image

I'm new to python and am not really sure how importing libraries works, but I understand that you are supposed to use "from PIL import Image" in order to import the Image module (is it even called a module???) and then use Image.open("filename") in order to open the Image, but I got a "No module named 'PIL'" error when I tried to import it from PIL. I then just did "import Image" which didn't raise any error flags but I still can't use Image.open without getting an "Undefined variable from import" error.

Any help is appreciated!

Upvotes: 0

Views: 261

Answers (2)

Omnikar
Omnikar

Reputation: 337

You need to install Pillow in order to use PIL
In your command line, type:

$ pip install Pillow

After that, you can use from PIL import Image

Upvotes: 1

Siddhesh Agarwal
Siddhesh Agarwal

Reputation: 189

In Python, you may sometimes need to install a library before using it. To install a library goto command prompt and type this command:

pip3 install Pillow

you will see some stuff install and if you get no error message, you are good to go. Now rerun your program.

Upvotes: 0

Related Questions