Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 383
ApPeL Avatar asked Jun 19 '10 08:06

ApPeL


3 Answers

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.

like image 84
Joe J Avatar answered Nov 14 '22 05:11

Joe J


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.

like image 3
gordon86 Avatar answered Nov 14 '22 05:11

gordon86


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.

like image 2
rescdsk Avatar answered Nov 14 '22 04:11

rescdsk