I encountered a problem when I am installing PIL under a virtualenv. I installed it with easy_install, the output said it was installed, but however, I can’t import it under the virtual environment. I got an ImportError when I tried to import it. Then I inspected the directory of PIL in site-packages directory, I noticed that it didn’t contain egg information in the directory. Also, the path in .pth file to PIL is “PIL”, and you can only see content of PIL in that directory. What does this mean? When you tried to import PIL, it looks every path in sys.path and see are there a package PIL? But the files Python can only see is something like this inside the directory:
… and other files of PIL
See? Python can only see __init__ and those stuff belong to PIL, but it can’t find the package PIL, that’s why it failed. To solve this issue, it is simple, just create another PIL directory in the original PIL directory, and move every in it into the new sub PIL directory. They you will get something like this:
other PIL sutff here …
That’s it! Now python can see and find the PIL package. Surely, the release of PIL it is broken, but fortunately, it is not difficult to fix. Hope this article could be helpful for people who also encountered this problem.