4
votes

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.

2
Is the PIL library on your python path?Exelian
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
@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

2 Answers

7
votes

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/

1
votes

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