简体   繁体   中英

Cannot import name 'Image'

I'm trying to set up Python Imaging Library, but I'm getting an error.

>>> from imaging import Image
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'Image'

I've set up Python 3.5.2 on Windows 10. The over-arching goal here is to use an image processing library to analyze some images. I want to do things like count all non-white (or relatively white) pixels, note their positions and then compare with another similar image.

My directory:

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

You are importing a wrong module. To install PIL I used

 pip install pillow

then you can use:

from PIL import Image

in your python code.

您可能将您的项目命名为“PIL.py”,请更改它:)

In my case, it was the issue with the case of the package name. Use pip install Image rather than pip install image

If you have saved your file with the name "PIL.py" then it's a problem. In my case, I did the same thing that's why I was here to find the solution. When I changed the name of the file then it worked properly.

Actually, we can't save a python file with the exact same name as a python library which we are going to use in that file.

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