PIL error: The _imaging C module is not installed
I have PIL (Python imaging library) installed.
When I run Python:
import PIL
import Image
import 开发者_开发百科_imaging
I don't get errors. However, when running my app, it raises
The _imaging C module not installed
I posted this response on the link that you sent (thank you for that), but figured I'd post on source as well. Sorry for the dupe post.
I was hoping that there was a way to do this without recompiling stuff. I happen to be using virtualenv. I did find that if I blew away my virtual env install and then reinstall with pip, the Imaging started to work again. These steps seemed to work (note, I’m using OSX)
Not sure if this mattered, but checking to see if jpeg is installed
winesap:~ $ port installed | grep -i jpeg
jpeg @7_0
jpeg @8a_0 (active)
Make sure I have PIP installed
sudo port -v install py26-pip
Remove the old virtual environment I had and recreate it
rm -rf ve
virtualenv –no-site-packages –distribute ve
. ./ve/bin/activate
Install pil and django into the virtualenv
echo “pil” > requirements.pip
echo “django” >> requirements.pip
pip-2.6 install -E ./ve/ -r requirements.pip
Test to see if the import works now. Note lack of obnoxious C module error
python
>>import import ImageFont
>>
Hope this is useful.
On Windows, remove _imaging.pyd and _imagingft.pyd inside C:\Python27. Leave all _imaging modules inside the C:\Python27\Lib\site-packages\PIL folder.
It works for me.
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.
why the problem exists, is with PIL 1.1.6? (only 1.1.7), Is that the version 1.1.6 does not use these libraries?
PIL 1.1.6 also uses its internal C library to speed things up.
For Windows you should use the precompiled packages. http://www.pythonware.com/products/pil/ offers X86 Windows binaries for 1.1.7. You might run into a problem with 1.1.7 Windows binaries. The freetype C library references a debug CRT that is not available on all machines. You can easily patch the _imagingft.pyd file with a hex editor.
I was completely missing the _imaging.*
files in the lib/site-packages/PIL
folder.
I downloaded the egg from here (the correct file depends on the platform):
https://pypi.python.org/pypi/Pillow/2.7.0
renamed it from .egg to .zipand copied all the files in the folder
PILthat start with
_imagingto the folder
lib/site-packages/PIL`.
.. Problem solved
On Ubuntu, the following command helped me (thanks to this answer on askubuntu):
sudo apt-get install libjpeg62:i386
精彩评论