您的位置:首页 > 编程语言 > Python开发

python PIL ImportError: The _imagingft C module is not installed

2012-07-06 16:40 781 查看
# import _imaging : No module named _imaging

# 需要先安装jpeg库

wget http://www.ijg.org/files/jpegsrc.v7.tar.gz
tar -zxvf jpegsrc.v7.tar.gz

cd jpeg-7

CC="gcc -arch x86_64"

./configure --enable-shared --enable-static

make

make install

# 然后再安装PIL库

wget http://effbot.org/downloads/Imaging-1.1.6.tar.gz
tar -zxvf Imaging-1.1.6.tar.gz

cd Imaging-1.1.6

rm -rf build

# 设置JPEG库的路径

vim setup.py :

JPEG_ROOT = libinclude("/usr/local")

python2.5 setup.py build

python2.5 setup.py install

# 把JPEG加入到系统库路径

echo '/usr/local/lib' >> /etc/ld.so.conf

ldconfig

# OK,完成

上述操作完成后就不会再报找不到 _imaging 的错误了。

别高兴太高,如果用到了freetype2,还会报_imagingft找不到。解决办法类似,先安装freetype2,在安装PIL里指定freetype2路径,将freetype2加到系统库路径中即可。


Building PIL with Freetype2 on Snow Leopard

7 july 2011

13:25
I had some trouble getting the venerable Python Imaging Library (PIL) compiled
with the Freetype feature on Mac OS X 10.6. Doing a simple
pip install
or
easy_install
will
build it with just the basic options. But if you need to generate Captchas and the like (with django-simple-captcha,
for example) you'll need the Freetype option, too.
In fact, OS X comes with Freetype2 installed (as part of the X11 package), just not in a location the PIL build script knows about. That is simple to fix, however:
$ cd ~/Downloads
$ curl -LO http://effbot.org/downloads/Imaging-1.1.7.tar.gz $ tar -zxf Imaging-1.1.7.tar.gz
$ cd Imaging-1.1.7
$ echo 'FREETYPE_ROOT = "/usr/X11/lib", "/usr/X11/include"' > setup_site.py
$ python setup.py build

The setup summary printed out at the end of the build should now say “FREETYPE2 support available”, which would mean this procedure worked as designed.

CODE: SELECT
ALL
#!usr/bin/env
python

from PIL import Image, ImageDraw, ImageFont

scribble = "Hello World"

img = Image.new("RGB", (200,200))

canvas = ImageDraw.Draw(img)

the_font = ImageFont.load_default() # truetype("Arial.ttf", 24)

canvas.text((0,0), scribble, font=the_font)

img.save(open("weather.png", "wb"), "PNG")


Hi, the code above works just fine, but when I replace load_default() with truetype("Arial.ttf", 24) I get the error...

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

File "/usr/lib/python2.6/dist-packages/PIL/ImageFont.py", line 218, in truetype

return FreeTypeFont(filename, size, index, encoding)

File "/usr/lib/python2.6/dist-packages/PIL/ImageFont.py", line 134, in __init__

self.font = core.getfont(file, size, index, encoding)

IOError: cannot open resource

...so it looks like it has a problem with opening the resource, which I'm thinking is something do with finding Arial.ttf. I'm not really knowledgeable on how linux handles fonts. I did look in the various fonts folders and found there is Ariel.ttf so I'm kind
of stuck about how to make things play nice.

Any ideas how I can get python to see my fonts? Is there any python code I could run to see which fonts it can see in Linux (I'm running Linux Mint 9)?

Thanks in advance.





leke
New Python User



Posts: 31
Joined: Sun Apr 11, 2010 10:40 am
Location: Oulu, Finland



Top


Re:
Python, Linux and the PIL



by mariostg »
Sun Dec 05, 2010 6:55 pm

Specify the full path

CODE: SELECT
ALL
the_font
= ImageFont.truetype("/usr/share/fonts/TTF/arial.ttf", 24)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐