81

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:\Python26\Lib\site-packages\PIL\ImageFont.py", line 34, in __getattr__
  raise ImportError("The _imagingft C module is not installed")
bluish
  • 26,356
  • 27
  • 122
  • 180
user483144
  • 1,431
  • 4
  • 14
  • 13

17 Answers17

85

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.

Marek Sapota
  • 20,103
  • 3
  • 34
  • 47
Sindre Myren
  • 999
  • 6
  • 8
  • There is an error in the "aptitude install aptitude install" ;) – anders Jun 14 '12 at 11:46
  • 12
    This doesn't work for me (Ubuntu 12.04, pip 1.1.7, Python 2.7). I uninstalled pip, apitude installed libfreetype6-dev, then ran `sudo pip install --upgrade pil`, but the problem persists. – Matthew Flaschen Dec 12 '12 at 00:41
  • Didn't work for me either (on Mac). I installed libfreetype from source (from [here](http://download.savannah.gnu.org/releases/freetype/)), then ran `sudo pip install --upgrade pil`, but was told that PIL was up to date. Quite python and reran the original script, got the same error. – scubbo Feb 04 '13 at 05:05
  • 2
    This worked for me on Xubuntu. sudo apt-get install libfreetype6-dev. And then in my virtualenv i ran, pip install Pillow (without sudo). You don't want to sudo pip in virtual environments. – pymarco Dec 04 '13 at 16:47
  • @pymacro: As you say, you don't want to sudo a pip install if you use a virtualenv. You probably also don't want to sudo any pip or easy_install operation if you can avoid it, as installing things outside of your distor's package management system makes your install kind of dirty. I wanted to keep this comment as short as poosible and still work though. Please take proper care of your Linux install:-) – Sindre Myren Feb 12 '14 at 11:51
  • This didn't work for me because of the cached version of pillow. I needed to `pip uninstall pillow` and then delete `~/.cache/pip/.../pillow*` and then `pip install pillow`. Once pillow got recompiled everything worked properly. – Kurt Sep 09 '15 at 17:04
  • 1
    For the reference of anyone still getting this issue, @Rafay's solution on using `pip install --no-cache-dir pillow` might help. – Sindre Myren May 17 '17 at 21:52
  • @scubbo I face with Could not find a version that satisfies the requirement pil in mac high sierra – Yuseferi Apr 03 '18 at 10:37
  • @SindreMyren Thanks for this. I had to do the `pip uninstall` and `install` to get it to work. – Torrien Jun 09 '20 at 00:30
57

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/

bluish
  • 26,356
  • 27
  • 122
  • 180
Imran
  • 87,203
  • 23
  • 98
  • 131
55

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
Rafay
  • 6,108
  • 11
  • 51
  • 71
17

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
fsw
  • 3,595
  • 3
  • 20
  • 34
  • use the first command to install *devel and then install python-imaging using "yum" (in epel repository) to get image displayed. – fanchyna Oct 23 '14 at 19:17
14

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
suzanshakya
  • 3,524
  • 1
  • 26
  • 22
  • 1
    Didn't work for me - after each line `ln -s ...` I got `ln: /usr/local/lib/libfreetype.dylib: File exists`. Problem persists. Do you have any more ideas? – scubbo Feb 04 '13 at 05:14
  • Would you try `ln -sf`? `f` overwrites the existing files, so make sure to backup the existing files. – suzanshakya Feb 04 '13 at 10:29
  • Just tried `ln -sf`, as recommended. After the first such line, I got `ln: /usr/local/include//freetype2: Operation not permitted`. Repeating the operation with `sudo` gave the same error. – scubbo Feb 04 '13 at 18:13
  • I'm on Mavericks, and /usr/X11/include/freetype2 does not exist on my system. – volvox Jul 29 '14 at 09:14
  • 1
    @volvox, try installing freetype with `brew install freetype`. – suzanshakya Jul 29 '14 at 10:46
  • 1
    @suzanshakya thanks that worked perfectly (once I'd installed homebrew). – volvox Jul 29 '14 at 15:57
12

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
Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Roshambo
  • 2,692
  • 1
  • 27
  • 24
  • If it doesn't work, add `brew link freetype` before install PIL. – user805627 Oct 09 '12 at 21:37
  • 1
    also the package is called `freetype` for macports users. – DanH Feb 21 '13 at 06:02
  • 1
    I had to reinstall `freetype` and `libjpeg` through brew and then relink them using `brew link --overwrite freetype` and `brew link --overwrite libjpeg`, then reinstalled `pil`, then it finally worked. Hope this helps anyone – gitaarik Jun 20 '13 at 14:23
  • `brew install pil` return error: `ImportError: The _imagingft C module is not installed` – Deng Haijun Apr 26 '16 at 13:40
12

Worked for Ubuntu 12.10:

sudo pip uninstall PIL
sudo apt-get install libfreetype6-dev
sudo apt-get install python-imaging
DmitrySandalov
  • 3,879
  • 3
  • 23
  • 17
  • 2
    I changed the third line from "sudo apt-get install python-imaging" to "pip install PIL" and it worked. – zephyr Jul 08 '13 at 23:55
  • 1
    Worked for me on debian, note that I had libjpeg-dev zlib1g-dev libpng12-dev already installed – cgl Dec 26 '14 at 23:13
2

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.

Community
  • 1
  • 1
Bovard
  • 1,175
  • 1
  • 14
  • 22
2

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!!

Joe Holloway
  • 28,320
  • 15
  • 82
  • 92
Jason Huang
  • 249
  • 3
  • 4
2

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
minzwurst
  • 61
  • 3
1

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

milton
  • 988
  • 6
  • 19
1

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

1

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!

Yun.Lu
  • 61
  • 5
1

Instead of running: pip install Pillow

Run: pip install Image

darwin Big Sur pyenv

xbalazsyf
  • 11
  • 1
1

In Windows 11 we need to solve this problem 'pip install --upgrade pip' 'pip install --upgrade Pillow'

pip install --upgrade Pillow

Nick ODell
  • 15,465
  • 3
  • 32
  • 66
  • 2
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 27 '22 at 11:12
0

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

Nick ODell
  • 15,465
  • 3
  • 32
  • 66
joest
  • 2,896
  • 1
  • 13
  • 6
0

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
Piotr Czapla
  • 25,734
  • 24
  • 99
  • 122