Python: The _imagingft C module is not installed
Solution 1
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/
Solution 2
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.
Solution 3
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
Solution 4
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
Solution 5
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
Related videos on Youtube

user483144
Updated on July 05, 2022Comments
-
user483144 6 months
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")
-
Imran about 12 yearsIf you want linux binaries you'll have to get it from your distro's software repository I guess.
-
noway about 12 yearsThis was exactly what I needed to get TTF support on Windows. The PIL binaries on the official page were having sxs issues when loading _imagingft.pyd. Thanks!
-
Piotr Sobczyk about 11 yearsThanks a lot! It helped me instantly!
-
anders over 10 yearsThere is an error in the "aptitude install aptitude install" ;)
-
user805627 about 10 yearsIf it doesn't work, add
brew link freetype
before install PIL. -
Matthew Flaschen about 10 yearsThis 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. -
scubbo almost 10 yearsDidn't work for me either (on Mac). I installed libfreetype from source (from here), 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 almost 10 yearsDidn't work for me - after each line
ln -s ...
I gotln: /usr/local/lib/libfreetype.dylib: File exists
. Problem persists. Do you have any more ideas? -
suzanshakya almost 10 yearsWould you try
ln -sf
?f
overwrites the existing files, so make sure to backup the existing files. -
scubbo almost 10 yearsJust tried
ln -sf
, as recommended. After the first such line, I gotln: /usr/local/include//freetype2: Operation not permitted
. Repeating the operation withsudo
gave the same error. -
DanH almost 10 yearsalso the package is called
freetype
for macports users. -
martineau over 9 yearsNowadays you can also get Pillow from PyPI - the Python Package Index.
-
gitaarik over 9 yearsI had to reinstall
freetype
andlibjpeg
through brew and then relink them usingbrew link --overwrite freetype
andbrew link --overwrite libjpeg
, then reinstalledpil
, then it finally worked. Hope this helps anyone -
zephyr over 9 yearsI changed the third line from "sudo apt-get install python-imaging" to "pip install PIL" and it worked.
-
LA_ over 9 yearsLooks like there is no PIL (not Pillow) any more. Is there any other source to download it?
-
Imran over 9 years@LA_ Pillow is a drop-in replacement for PIL
-
pymarco about 9 yearsThis 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.
-
Sindre Myren almost 9 years@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:-)
-
volvox over 8 yearsI'm on Mavericks, and /usr/X11/include/freetype2 does not exist on my system.
-
suzanshakya over 8 years@volvox, try installing freetype with
brew install freetype
. -
volvox over 8 years@suzanshakya thanks that worked perfectly (once I'd installed homebrew).
-
fanchyna about 8 yearsuse the first command to install *devel and then install python-imaging using "yum" (in epel repository) to get image displayed.
-
cgl almost 8 yearsWorked for me on debian, note that I had libjpeg-dev zlib1g-dev libpng12-dev already installed
-
Kurt over 7 yearsThis 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 thenpip install pillow
. Once pillow got recompiled everything worked properly. -
LennyLip almost 7 yearsThanks for the cache! Also, we can remove pip cache before re install Pillow: rm -rf ~/.cache/pip
-
MegaBytes almost 7 yearsthe second option worked for me. Thanks @tc_geophysics
-
Deng Haijun over 6 years
brew install pil
return error:ImportError: The _imagingft C module is not installed
-
azuax over 6 yearsJust a comment, in CentOS 6: yum install freetype-devel libjpeg-devel libpng-devel
-
soloice almost 6 yearsThanks! Works for me!
-
Sindre Myren over 5 yearsFor the reference of anyone still getting this issue, @Rafay's solution on using
pip install --no-cache-dir pillow
might help. -
Yuseferi over 4 years@scubbo I face with Could not find a version that satisfies the requirement pil in mac high sierra
-
Saurabh Ariyan over 4 yearswon't
sudo pip
affect the global pil rather than the virtual environment pil? -
Torrien over 2 years@SindreMyren Thanks for this. I had to do the
pip uninstall
andinstall
to get it to work. -
Ruli about 2 yearswhat does "darwin Big Sur pyenv" mean?
-
Ryu Kent almost 2 years@Ruli it means he's using MacOS (darwin), the version is Big Sur and his python setup is via pyenv.