Search code examples
pythonpython-3.xdebianpython-imaging-libraryraspbian

Raspbian-Python3.9: ImportError: The _imagingft C module is not installed


I'm trying to run a simple code using PIL with custom fonts in Python3.9 in Raspbian, but i can't go past this error:

Traceback (most recent call last):
  File "/home/pi/python/src/mintest.py", line 2, in <module>
    font52 = ImageFont.truetype('fonts/Font.ttf', 52)
  File "/home/pi/.local/lib/python3.9/site-packages/PIL/ImageFont.py", line 878, in truetype
    return freetype(font)
  File "/home/pi/.local/lib/python3.9/site-packages/PIL/ImageFont.py", line 875, in freetype
    return FreeTypeFont(font, size, index, encoding, layout_engine)
  File "/home/pi/.local/lib/python3.9/site-packages/PIL/ImageFont.py", line 196, in __init__
    if core.HAVE_RAQM:
  File "/home/pi/.local/lib/python3.9/site-packages/PIL/ImageFont.py", line 70, in __getattr__
    raise ImportError("The _imagingft C module is not installed")
ImportError: The _imagingft C module is not installed

This is the minimum code needed to reproduce the error in Raspbian:

from PIL import ImageFont   
font52 = ImageFont.truetype('fonts/Font.ttf', 52)

This is my system info

Distributor ID: Raspbian

Description: Raspbian GNU/Linux 9.13 (stretch)

Release: 9.13

Codename: stretch

Python 3.9.6

Output of python3 -m PIL

I already tried all the answers i saw here.


Solution

  • Normally, I would have expected the solution to the issue:

    The _imagingft C module is not installed
    

    to be installing the Freetype library with:

    sudo apt install libfreetype6-dev libfreetype6
    

    However, it seems that the solution is:

    sudo apt-get install libjpeg62-turbo-dev
    pip3 install Pillow --no-binary :all:
    

    I have no idea why - there is a discussion here.