简体   繁体   中英

“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!

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM