I have PIL (Python imaging library) installed.
When I run Python:
import PIL
import Image
import _imaging
I don\'t get errors. Howe
Here's some things that might help you if from PIL import Image
works but import _imaging
fails. If Image
fails too, see the Note at the end.
On Ubuntu 13.04 (raring), I had this problem. It turns out that Ubuntu installs _imaging.so
in a place that App Engine does not expect: /usr/lib/python2.7/dist-packages
instead of /usr/lib/python2.7/dist-packages/PIL
. So _imaging.so
was not anywhere in sys.path
.
Here are a couple ways around this:
Put the PIL C modules somewhere already on the path:
I noticed that /path/to/google_appengine/lib/PIL-1.1.7
was in sys.path
, but the directory did not exist in my installation. So I created the directory and copied the .so files into it, and everything worked. You would have to do this again, every time you updated the App Engine SDK, but at least it doesn't mess with the code you're developing.
Manipulate sys.path in main.py
:
This code will check whether we're running the dev appserver, and if so, add the correct dir to the path. Untested but it should work ;)
# Find _imaging.so and put its directory here.
# `locate _imaging.so` or `dpkg -L python-imaging`
PIL_PATH = '/usr/lib/pyshared/python2.7/'
PRODUCTION_MODE = not os.environ.get(
'SERVER_SOFTWARE', 'Development').startswith('Development')
if not PRODUCTION_MODE:
sys.path.insert(PIL_PATH)
I suppose that this might make more than just the PIL modules available to you, so that would introduce (yet more) differences between development and production. Also, this technique involves modifying the source code of your app, which seems like a bad call if there's more than one person developing it.
Note: If import Image
fails, you might have forgotten to add the PIL library to your app.yaml
.
libraries:
- name: PIL
version: "latest"
You might need to restart your dev_appserver.py
after adding this library for the changes to be reflected in e.g. the interactive console.