pythonpython-imaging-libraryeasy-install

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

  • 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).