开发者

No module named _imagingft

开发者 https://www.devze.com 2023-02-10 01:04 出处:网络
I have this problem: No module named _imagingft I have installed PIL, but it still does not work. I use O开发者_高级运维SX.

I have this problem:

No module named _imagingft

I have installed PIL, but it still does not work. I use O开发者_高级运维SX.

I'm trying to install this module for Django Simple Captcha.


Installing Pillow over existing PIL solved the issue for me:

$ sudo easy_install PIL
$ sudo easy_install Pillow


The suggest of Cristopher works very well for me.

Details follow: 1. Uninstall existing Python Imaging Library

  1. Download and extract the source version (from here http://effbot.org/downloads/Imaging-1.1.6.tar.gz)

  2. Install freetype2 library (you need freetype cause _imagingft handles TrueType fonts for captcha)

  3. Modify setup.py (in PIL extracted source folder)to match the freetype2 library (e.g. on my VPS with Centos I've changed line 'FREETYPE_ROOT = None' to 'FREETYPE_ROOT = "/usr/local/include"')

  4. Build PIL (python setup.py build) and verify that Freetype2 support is ok

  5. Install PIL (python setup.py build)

  6. After installing you could verify existence of library, opening python console and typing 'import instructions for _imagingft library'.

If you use ubuntu you can use following manual: http://helloworld.infobart.com/compiling-pil-on-ubuntu-natty


Thanks to a combination of resources (credit at the end) I've put together the following script, which works for me but YMMV. (Please check it carefully before running. It may have bugs that'll eat your liver, shave your cat, and run your car on leaded fuel):

#!/bin/bash

pip-2.6 uninstall PIL
# Just in case there's a virtualenv someplace:
pip uninstall PIL
# And forcibly clean up PIL as well
rm -rf /Library/Python/2.6/site-packages/PIL*

if [ ! -d "/usr/X11/include/freetype2" ];then
    echo "You need to have XCode installed with the freetype libraries"
    exit 1
fi

# Ok we're good to install ...
# Freetype is installed by XCode, so let's link to that for PIL's
# setup.py to know where to find things
ln -s /usr/X11/include/freetype2 /usr/local/include/ 
ln -s /usr/X11/include/ft2build.h /usr/local/include/ 
ln -s /usr/X11/lib/libfreetype.6.dylib /usr/local/lib/ 
ln -s /usr/X11/lib/libfreetype.6.dylib /usr/local/lib/libfreetype.dylib 

pip-2.6 install PIL
# OR
# pip-2.6 install http://effbot.org/downloads/Imaging-1.1.7.tar.gz

Credits:

  • http://groups.google.com/group/python-virtualenv/browse_thread/thread/d42f8fd2c52e88b7
  • The stuff above


Looks like your PIL install didn't support Freetype. You may be missing some Freetype libraries and so your PIL install skipped support for it.

Freetype is the technology for handling fonts.


I was struggling with this myself. The solution is to install Pillow instead of PIL.

Excerpts From https://pypi.python.org/pypi/Pillow/2.0.0:

Pillow is the "friendly" PIL fork by Alex Clark and Contributors. PIL is the Python Imaging Library by Fredrik Lundh and Contributors.

PIL is not setuptools compatible. ... Also, PIL's current bi-yearly (or greater) release schedule is too infrequent to accomodate the large number and frequency of issues reported.

The binary distribution for Windows also includes _imagingft. You no longer need to build your own from sources.

Download the installer packages from: https://pypi.python.org/pypi/Pillow/2.0.0#downloads

Or simply install with pip install pillow


I ran into a similar problem and the following solution worked for me, hence, I figured I would post it. Hopefully, it will help someone else while they try out the numerous solutions.

Firstly, I think some of the solutions up here will also work and I did use some of the above solutions as a spring board for my own.

[My Setup]
I run in my development virtual environment.

Mac OS X 10.7
pip
Django 1.3.1
XCode 4.2.1

I found that freetype2 is already included with your Mac OS X installation in /usr/X11/include

I am not sure if it is installed with XCode or just comes by default but from what I read and understood there are some patent issues which expired in 2010 which is why Apple does not 'turn on' the font library by default.

I had already installed libjpeg prior to install PIL using HomeBrew.

$ brew install libjpeg

Initially, I installed PIL using pip, but later uninstalled it and instead chose to install Pillow

Believe me or not, that just worked for me.

$ pip install Pillow

It seems like Pillow does the hairy work for you of linking and including the source from /usr/X11/lib as is show below in the installation procedure output:

Running setup.py install for Pillow --- using frameworks at /System/Library/Frameworks building '_imaging' extension llvm-gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -DHAVE_LIBJPEG -DHAVE_LIBZ -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -I/usr/x11/include/freetype2 -IlibImaging -I/opt/local/include -I/usr/x11/include -I/Users//.virtualenvs/canoe_django_env/include -I/usr/local/include -I/usr/include -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _imaging.c -o build/temp.macosx-10.7-intel-2.7/_imaging.o

I hope this helps as it worked for me.
Sincerely.


Solution without modifying PIL source code:

  1. install freetype2-dev package
  2. export FREETYPE_ROOT=$(pkg-config --variable=libdir freetype2) # you can change to {path-to-freetype-library} if pkg-config is not available
  3. install latest PIL version (pip install https://bitbucket.org/effbot/pil-2009-raclette/get/6a64b3083e35.tar.bz2)

Related PIL issue.


Another possible solution, if you're using Homebrew:

brew install freetype
brew install Pillow
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号