[triangle-zpug] can't find font problem

David Handy david at handysoftware.com
Mon Mar 31 03:57:54 CEST 2008

On Sun, Mar 30, 2008 at 06:21:35AM -0700, Joseph Mack NA3T wrote:
> There's demo code out there eg
> http://www.pythonware.com/library/pil/handbook/imagefont.htm
> http://www.livibetter.com/blog/2006/11/24/making-pil-font-for-python-image-library/
> (look for "arial.pil")
> that finds the font without doing anything special. I 
> thought that maybe there was some font path or python path 
> that allowed python to find the file without me having to do 
> anything.

In these examples, they are loading "arial.pil" from the current working
directory, whatever that happens to be at the time the script is run. That
is not production-quality code, it was simplified for demo purposes.

> I moved the files from directory to directory, hoping they'd 
> be picked up by the load command. Their current location is 
> just where they are now. If there's a canonical location, 
> I'd be happy to move them there.

Typically, I put font files with my application.  Any Python application
more complicated than a single .py file I usually put into a Python package
directory (a directory with an __init__.py file, see
http://docs.python.org/tut/node8.html#SECTION008400000000000000000). I throw
the fonts and other static data files in the same package directory as the
.py files, and then use the technique I described in my previous email to
locate the package directory, and load files relative to that directory.

Example file layout:

        python startapp.py
        python startup.py
        import myapp.mainmodule
            def main():

I don't know if this is "canonical", but I've seen a lot of Python
applications deployed this way. Using this technique, it is pretty easy to
make your applications cross-platform compatible. Just zip up
ApplicationHome and you've got something you can take to another machine and

David H

David Handy
Computer Programming is Fun!
Beginning Computer Programming with Python

More information about the TriZPUG mailing list