4

I'm learning a little Django with the Python Web Development with Django book. All was going well until I tried to build the photos application which requires the PIL (Python Imaging Library). When I try to add an image through the admin interface I receive an error message pasted below.

I am running Windows 7, Python 2.7, Django 1.3b1, and XAMPP 1.7.3 with the wsgi module successfully installed (at least I think so, since the rest of my Django experiments work fine).

Following the troubleshooting guide from the PIL site I have tried to import the PIL modules at the Python prompt:

>>>import _imaging
>>>import Image

Both work fine, without displaying an error. However, trying to run the Django admin app that uses PIL results in:

ImportError at /admin/items/photo/add/ The _imaging C module is not installed Request Method: POST Request URL: http://localhost:8888/photos/admin/items/photo/add/ Django Version: 1.3 beta 1 SVN-15679 Exception Type: ImportError Exception Value:
The _imaging C module is not installed Exception Location: C:\Python27\lib\site-packages\PIL\Image.py in getattr, line 37 Python Executable: C:\xampp\apache\bin\httpd.exe Python Version: 2.7.0 Python Path:
['C:\Python27\lib\site-packages\ipython-0.10-py2.7.egg', 'C:\Python27\lib\site-packages\sqlalchemy-0.6.4-py2.7.egg', 'C:\Python27\lib\site-packages\openglcontext_full-2.1.0a7-py2.7.egg', 'C:\Python27\lib\site-packages\ttfquery-1.0.4-py2.7.egg', 'C:\Python27\lib\site-packages\fonttools-2.3-py2.7-win32.egg', 'C:\Python27\lib\site-packages\pydispatcher-2.0.2-py2.7.egg', 'C:\Python27\lib\site-packages\pyside-1.0.0beta1qt471-py2.7-win32.egg', 'C:\code\ots', 'C:\lib\django', 'C:\code', 'C:\xampp', 'C:\Windows\system32\python27.zip', 'C:\Python27\Lib', 'C:\Python27\DLLs', 'C:\Python27\Lib\lib-tk', 'C:\xampp\apache\bin', 'C:\Users\garethconner\AppData\Roaming\Python\Python27\site-packages', 'C:\Python27', 'C:\Python27\lib\site-packages', 'C:\Python27\lib\site-packages\PIL', 'C:\lib\django\django', 'C:\Python27\lib\site-packages\win32', 'C:\Python27\lib\site-packages\win32\lib', 'C:\Python27\lib\site-packages\Pythonwin', 'C:\Python27\lib\site-packages\setuptools-0.6c11-py2.7.egg-info', 'C:\Python27\lib\site-packages\wx-2.9.1-msw', 'C:\code']

Any help would be greatly appreciated.

gbc
  • 8,455
  • 6
  • 35
  • 30
  • Is the PIL library on your python path? – Exelian Mar 18 '11 at 14:04
  • Does the command lines work when ran from python manage.py shell? Does the pb occur when the site is served with python manage.py runserver? – luc Mar 18 '11 at 14:19
  • @Exelian: Yes, it's hard to pick out in that dump, but it is on the python path. On the command line, python can import the module. – gbc Mar 18 '11 at 14:24

2 Answers2

7

I've answered this before here

Just install pre-compiled binaries for Windows (for your python version) from http://www.lfd.uci.edu/~gohlke/pythonlibs/

Community
  • 1
  • 1
Imran
  • 87,203
  • 23
  • 98
  • 131
  • Thanks so much, that worked perfectly. Sorry that I missed your previous answer. I searched on SO and found a bunch of suggestions that didn't work but somehow missed yours. – gbc Mar 18 '11 at 14:23
1

This worked for me when the same installer (windows, Python2.7) downloaded from the official PIL site did not. Thanks!

Simeon
  • 421
  • 2
  • 6
  • +1 for this advice - I had already tried reinstalling from the official PIL site and probably wouldn't have tried reinstalling *again* from this link if you hadn't said this. It seems the official PIL site's binaries are 32-bit only, even though it doesn't say that anywhere on their site. – danny Aug 28 '11 at 23:43