Py2EXE, PIL and ImageFont Error

Py2EXE, PIL and ImageFont Error

After using Py2EXE to generate a distributable binary from a project that used the Python Imaging Library (PIL) I got an error like this:

File “PIL\ImageFont.pyc”, line —, in load_path IOError: cannot find font file

A quick google yields this page: http://www.py2exe.org/index.cgi/PILAndFontfiles

Unfortunately dropping the files into the Dist directory wasn’t enough – when cycling through path directories to find the file it searches for …/dist/library.zip rather than simply /dist.

The fix is simple, edit your ImageFont.py file and in the load_path(filename) function, change:

def load_path(filename):
"Load a font file, searching along the Python path."
for dir in sys.path:
if Image.isDirectory(dir):

to:

def load_path(filename):
"Load a font file, searching along the Python path."
for dir in sys.path:
dir = os.path.dirname(dir)
if Image.isDirectory(dir):

This worked for me.

3 thoughts on “Py2EXE, PIL and ImageFont Error

Leave a Reply

Your email address will not be published. Required fields are marked *