8

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.

mkosmala
  • 1,437
  • 3
  • 12
  • 10
  • 3
    Can you paste the traceback? – Kobi K Dec 15 '13 at 15:39
  • 1
    check that your script uses the same python executable where you've installed Pillow e.g., add at the top of the Python script: `#!python3.3` if you have one one python3.3 installation. – jfs Dec 16 '13 at 00:57

3 Answers3

13

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.

MattDMo
  • 100,794
  • 21
  • 241
  • 231
  • Thanks, yep. The script is calling Python 2.7, not 3.3. – mkosmala Dec 16 '13 at 16:38
  • I needed Pillow 2.3.2, doesn't seem to be there :( – Zhianc Sep 11 '14 at 02:46
  • @Zhianc Gohlke's site isn't an archive. You can get previous versions from PyPI like [this](https://pypi.python.org/pypi/Pillow/2.3.2#downloads). You'll have to build from source, though. – MattDMo Sep 11 '14 at 03:10
1

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.

alexandrul
  • 12,856
  • 13
  • 72
  • 99
0

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 )
Saurabh
  • 7,525
  • 4
  • 45
  • 46