Question

I am fairly new to Python and trying to install the Pillow package on Windows 7. I downloaded and ran the MS Windows installer Pillow-2.2.1.win-amd64-py3.3.exe from here. It appeared to install fine. If I run the simple line of code:

from PIL import Image

directly from the Python interpreter, it runs fine. A help() on PIL gives me the package contents.

But when I try to run the same line of code from within a script, I get an ImportError: No module named PIL. What am I missing?

(Note that I've been able to import sys and import MySQLdb from within scripts just fine.)


Resolved: sure, enough, I'm running Python 2.7 when I run scripts. (I think I vaguely recall having to install an older version so I could interface with MySQL.) Thank you all for pointing out that I should check the version being used.

Was it helpful?

Solution

For third-party modules for Windows, my go-to resource is Christoph Gohlke's Python Extension Packages for Windows. You can find the latest version of Pillow here. Make sure you're working with the python.org version of Python.

As far as your specific error, it's hard to tell exactly without a traceback, but make sure your script is calling the correct version of Python. If you have also installed Python 2.7, for example, your script may be calling that instead of 3.3.

OTHER TIPS

In such cases I'm simply printing the sys.path at the beginning of the script in trouble and comparing it with the one from the working python interpreter. In most cases I was running the script with a different python interpreter.

In my case , I was referring to wrong pip folder. Changed virtual environment in pycharm to point to right pip folder to solve this issue

import sys
print ( sys.path )
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top