ImportError: No module named PIL
I use this command in the shell to install PIL:
easy_install PIL
then I run python
and type this: import PIL
. But I get this error:
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named PIL
I've never had such problem, what do you think?
Solution 1:
In shell, run:
pip install Pillow
Attention: PIL is deprecated, and pillow is the successor.
Solution 2:
On some installs of PIL, you must do
import Image
instead of import PIL
(PIL is in fact not always imported this way). Since import Image
works for you, this means that you have in fact installed PIL.
Having a different name for the library and the Python module is unusual, but this is what was chosen for (some versions of) PIL.
You can get more information about how to use this module from the official tutorial.
PS: In fact, on some installs, import PIL
does work, which adds to the confusion. This is confirmed by an example from the documentation, as @JanneKarila found out, and also by some more recent versions of the MacPorts PIL package (1.1.7).
Solution 3:
On a different note, I can highly recommend the use of Pillow which is backwards compatible with PIL and is better maintained/will work on newer systems.
When that is installed you can do
import PIL
or
from PIL import Image
etc..
Solution 4:
At first install Pillow with
pip install Pillow
or as follows
c:\Python35>python -m pip install Pillow
Then in python code you may call
from PIL import Image
"Pillow is a fork of PIL, the Python Imaging Library, which is no longer maintained. However, to maintain backwards compatibility, the old module name is used." From pillow installed, but "no module named pillow" - python2.7 - Windows 7 - python -m install pillow