allow scripts to use .pth files?

samwyse samwyse at gmail.com
Thu Jul 12 08:26:14 EDT 2007


On Jul 8, 3:53 pm, John Machin <sjmac... at lexicon.net> wrote:

> I'm curious whether you think that the OP's use of ".pth" was a typo,
> and whether you have read this:
>    http://docs.python.org/lib/module-site.html

I've read it, but not recently; the syntax of the .pyh files was in
the back of my head.  I had forgotten about the sitecustomize module,
though.  Unfortunately for the OP, while the documentation states,
"After these path manipulations, an attempt is made to import a module
named sitecustomize," the import is apparently done *before* the path
to the script is prepended to sys.path.  (My name isn't Luke, so I
don't feel the need to read the source.)

I'm guessing that the OP's real question is, "How does one do site
customizations when one doesn't have write access to the site
directories?"  Lots of programs can be installed and run from ~/bin,
but locating ~/lib can be hard, at least for arbitrary values of bin
and lib.  At this point, someone usually tells me to write a PEP;
perhaps the OP would like to try his hand?  In keeping with the spirit
of the site customizations, I'd specify that all .pyh files get
imported, not just one matching the name of the script.  (This is more
robust in the face of hard-links, packages consisting of multiple
scripts, etc.)  I'd also suggest an attempt to import a module named
mycustomize after the path to the invoked script is prepended to
sys.path.




More information about the Python-list mailing list