Python: The _imagingft C module is not installed

Question:

I’ve tried lots of solution that posted on the net, they don’t work.

>>> import _imaging
>>> _imaging.__file__
'C:\python26\lib\site-packages\PIL\_imaging.pyd'
>>>

So the system can find the _imaging but still can’t use truetype font

from PIL import Image, ImageDraw, ImageFilter, ImageFont


im = Image.new('RGB', (300,300), 'white')
draw = ImageDraw.Draw(im)
font = ImageFont.truetype('arial.ttf', 14)
draw.text((100,100), 'test text', font = font)

Raises this error:

ImportError: The _imagingft C module is not installed

File "D:Python26Libsite-packagesPILImageFont.py", line 34, in __getattr__
  raise ImportError("The _imagingft C module is not installed")
Asked By: user483144

||

Answers:

Your installed PIL was compiled without libfreetype.

You can get precompiled installer of PIL (compiled with libfreetype) here (and many other precompiled Python C Modules):

http://www.lfd.uci.edu/~gohlke/pythonlibs/

Answered By: Imran

On Ubuntu, you need to have libfreetype-dev installed before compiling PIL.

i.e.

$ sudo apt-get install libfreetype6-dev
$ sudo -s
# pip uninstall pil
# pip install --no-cache-dir pil

PS! Running pip install as sudo will usually install packages to /usr/local/lib on most Ubuntu versions. You may consider to install Pil in a virtual environment (virtualenv or venv) in a path owned by the user instead.

You may also consider installing pillow instead of pil, which I believe is API compatible: https://python-pillow.org. Note that Pillow also requires libfreetype-dev and you might need to follow the same uninstall/install steps if libfreetype-dev was not present during the initial installation.

Answered By: Sindre Myren

Ubuntu 11.10 installs zlib and freetype2 libraries following the multi-arch spec (e.g. /usr/lib/i386-linux-gnu). You may use PIL setup environment variables so it can find them. However it only works on PIL versions beyond the pil-117 tag.

export PIL_SETUP_ZLIB_ROOT=/usr/lib/i386-linux-gnu
export PIL_SETUP_FREETYPE_ROOT=/usr/lib/i386-linux-gnu
pip install -U PIL

Since your multi-arch path may be different (x86-64), it’s preferable to install the -dev packages and use pkg-config to retrieve the correct path.

pkg-config --variable=libdir zlib
pkg-config --variable=libdir freetype2

Another way given by Barry on Pillow’s setup.py is to use dpkg-architecture -qDEB_HOST_MULTIARCH to obtain the proper library directory suffix.

See https://bitbucket.org/effbot/pil-2009-raclette/issue/18

Answered By: milton

For OS X (I’m running 10.6 but should work for others) I was able to get around this error using the advice from this post. Basically you need to install a couple of the dependencies then reinstall PIL.

Answered By: Bovard

In OS X, I did this to solve the problem:

pip uninstall PIL
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 install PIL
Answered By: suzanshakya

Basically, you need to install freetype before installing PIL.

If you’re using Homebrew on OS X it’s just a matter of:

brew remove pil
brew install freetype
brew install pil
Answered By: Roshambo

Worked for Ubuntu 12.10:

sudo pip uninstall PIL
sudo apt-get install libfreetype6-dev
sudo apt-get install python-imaging
Answered By: DmitrySandalov

solution for CentOS 6 (and probably other rpm based):

yum install freetype-devel libjpeg-devel libpng-devel

pip uninstall pil Pillow
pip install pil Pillow
Answered By: fsw

The followed works on ubuntu 12.04:

pip uninstall PIL
apt-get install libjpeg-dev
apt-get install libfreetype6-dev
apt-get install zlib1g-dev
apt-get install libpng12-dev
pip install PIL --upgrade

when your see “– JPEG support avaliable” that means it works.

But, if it still doesn’t work when your edit your jpeg image, check the python path!!
My python path missed '/usr/local/lib/python2.7/dist-packages/PIL-1.1.7-py2.7-linux-x86_64.egg/', so I edit the ~/.bashrc add the following code to this file:

export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/dist-packages/PIL-1.1.7-py2.7-linux-x86_64.egg/

then, finally, it works!!

Answered By: Jason Huang

I used homebrew to install freetype and I have the following in /usr/local/lib:

libfreetype.6.dylib
libfreetype.a
libfreetype.dylib

But the usual:

pip install pil

Does not work for me, so I used:

pip install http://effbot.org/downloads/Imaging-1.1.6.tar.gz

Answered By: tc_geophysics

In my ubuntu12.04, after I installed python-imaging using apt-get, it works.

Answered By: joest

For me none of the solutions posted here so far has worked. I found another solution here: http://codeinthehole.com/writing/how-to-install-pil-on-64-bit-ubuntu-1204/

First install the dev packages:

$ sudo apt-get install python-dev libjpeg-dev libfreetype6-dev zlib1g-dev

Then create some symlinks:

$ sudo ln -s /usr/lib/`uname -i`-linux-gnu/libfreetype.so /usr/lib/
$ sudo ln -s /usr/lib/`uname -i`-linux-gnu/libjpeg.so /usr/lib/
$ sudo ln -s /usr/lib/`uname -i`-linux-gnu/libz.so /usr/lib/

Afterwards PIL should compile just fine:

$ pip install PIL --upgrade
Answered By: minzwurst

The following worked for me on Ubuntu 14.04.1 64 bit:

sudo apt-get install libfreetype6-dev

Then, in the virtualenv:

pip uninstall pillow
pip install --no-cache-dir pillow
Answered By: Rafay

In my Mac, the following steps in terminal works:

$ brew install freetype
$ sudo pip uninstall pil
$ sudo pip install pillow

hopes it works for you. Good luck!

Answered By: Yun.Lu

Instead of running: pip install Pillow

Run: pip install Image

darwin Big Sur pyenv

Answered By: xbalazsyf

In Windows 11 we need to solve this problem
‘pip install –upgrade pip’
‘pip install –upgrade Pillow’

pip install –upgrade Pillow

Answered By: shubham koli

Installing libtruetype-dev did not work for me on ubuntu container.
My pillow was not compiled and pip installed one without truetype. (maybe it was cached this way by docker container provider). What did work was installing pill ow via conda:

pip uninstall -y pillow    
conda install pillow
Answered By: Piotr Czapla