1

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:

enter image description here

enter image description here

enter image description here

16
  • 1
    from PIL import Image. Commented Dec 23, 2016 at 3:11
  • did you create file imaging.py with element Image inside ? PIL needs from PIL import Image Commented Dec 23, 2016 at 3:12
  • @ekhumoro that returns an error No module name 'PIL' Commented Dec 23, 2016 at 3:19
  • how did you install this imaging ? I don't have it in pip. Commented Dec 23, 2016 at 3:24
  • I just downloaded the zip file from Github Commented Dec 23, 2016 at 3:25

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

See my edited question - I put in the images of my directory. Assume that I've already downloaded, now I just need to know how to access it correctly.
@whatwhatwhat: I think you should install by "pip" or "easy install". You did not install the module correctly.
Or you can try this one: put __ init __.py in the folder and call the file with from imaging.PIL import Image
2

you probably named your project as "PIL.py", change it :)

2 Comments

This might be insightful. But it needs more explanation why it could cause the problem and how the proposed solution could help.
This was the cause for me, thank you! The error was "cannot import name 'Image' from partially initialized module 'PIL" (most likely due to a circular import)
0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.