Python: The _imagingft C module is not installed

83,738

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
Share:
83,738

Related videos on Youtube

user483144
Author by

user483144

Updated on July 05, 2022

Comments

  • user483144
    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
    Imran about 12 years
    If you want linux binaries you'll have to get it from your distro's software repository I guess.
  • noway about 12 years
    This 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
    Piotr Sobczyk about 11 years
    Thanks a lot! It helped me instantly!
  • anders
    anders over 10 years
    There is an error in the "aptitude install aptitude install" ;)
  • user805627
    user805627 about 10 years
    If it doesn't work, add brew link freetype before install PIL.
  • Matthew Flaschen
    Matthew Flaschen about 10 years
    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.
  • scubbo
    scubbo almost 10 years
    Didn'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
    scubbo almost 10 years
    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?
  • suzanshakya
    suzanshakya almost 10 years
    Would you try ln -sf? f overwrites the existing files, so make sure to backup the existing files.
  • scubbo
    scubbo almost 10 years
    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.
  • DanH
    DanH almost 10 years
    also the package is called freetype for macports users.
  • martineau
    martineau over 9 years
    Nowadays you can also get Pillow from PyPI - the Python Package Index.
  • gitaarik
    gitaarik over 9 years
    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
  • zephyr
    zephyr over 9 years
    I changed the third line from "sudo apt-get install python-imaging" to "pip install PIL" and it worked.
  • LA_
    LA_ over 9 years
    Looks like there is no PIL (not Pillow) any more. Is there any other source to download it?
  • Imran
    Imran over 9 years
    @LA_ Pillow is a drop-in replacement for PIL
  • pymarco
    pymarco about 9 years
    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.
  • Sindre Myren
    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
    volvox over 8 years
    I'm on Mavericks, and /usr/X11/include/freetype2 does not exist on my system.
  • suzanshakya
    suzanshakya over 8 years
    @volvox, try installing freetype with brew install freetype.
  • volvox
    volvox over 8 years
    @suzanshakya thanks that worked perfectly (once I'd installed homebrew).
  • fanchyna
    fanchyna about 8 years
    use the first command to install *devel and then install python-imaging using "yum" (in epel repository) to get image displayed.
  • cgl
    cgl almost 8 years
    Worked for me on debian, note that I had libjpeg-dev zlib1g-dev libpng12-dev already installed
  • Kurt
    Kurt over 7 years
    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.
  • LennyLip
    LennyLip almost 7 years
    Thanks for the cache! Also, we can remove pip cache before re install Pillow: rm -rf ~/.cache/pip
  • MegaBytes
    MegaBytes almost 7 years
    the second option worked for me. Thanks @tc_geophysics
  • Deng Haijun
    Deng Haijun over 6 years
    brew install pil return error: ImportError: The _imagingft C module is not installed
  • azuax
    azuax over 6 years
    Just a comment, in CentOS 6: yum install freetype-devel libjpeg-devel libpng-devel
  • soloice
    soloice almost 6 years
    Thanks! Works for me!
  • Sindre Myren
    Sindre Myren over 5 years
    For the reference of anyone still getting this issue, @Rafay's solution on using pip install --no-cache-dir pillow might help.
  • Yuseferi
    Yuseferi over 4 years
    @scubbo I face with Could not find a version that satisfies the requirement pil in mac high sierra
  • Saurabh Ariyan
    Saurabh Ariyan over 4 years
    won't sudo pip affect the global pil rather than the virtual environment pil?
  • Torrien
    Torrien over 2 years
    @SindreMyren Thanks for this. I had to do the pip uninstall and install to get it to work.
  • Ruli
    Ruli about 2 years
    what does "darwin Big Sur pyenv" mean?
  • Ryu Kent
    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.