Search code examples
python-2.7drawingpython-imaging-library

Fails to run a simple pillow example (can't find arial.pil)


Pillow was build under ubuntu 14.04 with pip install Pillow:

PIL SETUP SUMMARY
    --------------------------------------------------------------------
    version      Pillow 2.4.0
    platform     linux2 2.7.6 (default, Mar 22 2014, 22:59:38)
                 [GCC 4.8.2]
    --------------------------------------------------------------------
    *** TKINTER support not available
    (Tcl/Tk 8.6 libraries needed)
    --- JPEG support available
    *** OPENJPEG (JPEG2000) support not available
    --- ZLIB (PNG/ZIP) support available
    --- LIBTIFF support available
    --- FREETYPE2 support available
    --- LITTLECMS2 support available
    --- WEBP support available
    --- WEBPMUX support available
    --------------------------------------------------------------------
    To add a missing option, make sure you have the required
    library, and set the corresponding ROOT variable in the
    setup.py script.

    To check the build, run the selftest.py script.

    changing mode of build/scripts-2.7/pilfile.py from 644 to 755
    changing mode of build/scripts-2.7/pildriver.py from 644 to 755
    changing mode of build/scripts-2.7/pilconvert.py from 644 to 755
    changing mode of build/scripts-2.7/pilfont.py from 644 to 755
    changing mode of build/scripts-2.7/pilprint.py from 644 to 755
    changing mode of /usr/local/bin/pilfile.py to 755
    changing mode of /usr/local/bin/pildriver.py to 755
    changing mode of /usr/local/bin/pilconvert.py to 755
    changing mode of /usr/local/bin/pilfont.py to 755
    changing mode of /usr/local/bin/pilprint.py to 755
Successfully installed Pillow
Cleaning up...

But when running the following example:

from PIL import ImageFont, ImageDraw

draw = ImageDraw.Draw(image)

# use a bitmap font
font = ImageFont.load("arial.pil")

draw.text((10, 10), "hello", font=font)

# use a truetype font
font = ImageFont.truetype("arial.ttf", 15)

draw.text((10, 25), "world", font=font)

The code failed to find "arial.pil"


Solution

  • You're using this example code.

    First, do you have a file called arial.pil in the same directory? Type this to find out:

    ls arial.pil
    

    Do you have it anywhere on your computer?

    locate arial.pil
    

    Probably not, it's just example code. You probably don't want arial.pil anyway. (If you do, try these instructions.) Instead, replace arial.pil with a filename (with path) of a font on your system (for example, see here).