Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing Pillow for Python on Windows

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.

like image 726
mkosmala Avatar asked Dec 15 '13 15:12

mkosmala


2 Answers

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.

like image 105
MattDMo Avatar answered Sep 30 '22 17:09

MattDMo


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.

like image 37
alexandrul Avatar answered Sep 30 '22 18:09

alexandrul