python path - pdflib

Steve Holden sholden at holdenweb.com
Thu Nov 8 18:42:48 EST 2001


"steve" <steven.smith at level3.com> wrote ...
> I am trying to set a program to use a path in python.  I see that I
> can set my environment variable PYTHONPATH or set the sys.path in
> python to the dir I want.  I am having problems getting python to find
> the files I want in this path.
>
> I am using the pdflib to create a pdf file.  I need things that are in
> the fonts directory.  If I do a sym-link in the dir I am running my
> script from, everything works fine.  When I don't try to open up a
> file from a different directory, the fonts are loading correctly.
> When I open a file, then set the font type, it can't find the font,
> unless it is in the directory the script is being run from, even
> though I do a print sys.path and the directory is the first path
> listed.
>
> Has anyone seen this problem or know a fix for it?  I'm somewhat
> stumped.  It seems to me that it is a python/sys problem, because why
> would the sys module be affected by another module?  Maybe I'm wrong
> on this assumption.  As a note, I was using python 2.0 as this is what
> pdflib wants to use, but I have tried with 2.1.

You are mistaken in believeing that the Python path (effectively, sys.path)
affects how the system finds data files. The path mechanism is used only for
locating modules to be imported. You will therefore need to either locate
the data files in a known directory or programmatically try the directories
on the path until you find it.

Probably a good compromise is having a default location hard-wired into the
program, but allowing an environment variable (found in the os.environ
dictionary) to override the default if/when set.

regards
 Steve
--
http://www.holdenweb.com/








More information about the Python-list mailing list