Idea: PYTHONPATH_VER

David M. Cooke cookedm+news at physics.mcmaster.ca
Mon May 17 15:29:15 EDT 2004


At some point, Fernando Perez <fperez528 at yahoo.com> wrote:

> Peter Hansen wrote:
>
>> Having missed the discussion preceding, I'm probably off the mark,
>> but in my experience just about everything that can be solved with
>> PYTHONPATH can be handled with a .pth file as well, and I haven't
>> had any need to use PYTHONPATH for quite some time as a result.
>
> How do you handle the fact that .pth files are only read from certain places,
> and not others?  This problem has me currently rather stuck with gross hacks: 
> packages like Numeric, which rely on a .pth file instead of being a 'true'
> python package (with __init__.py), are very problematic.  I am trying to share
> Numeric from an NFS mounted directory for multiple clients, located
> at /usr/local/lib/python.  It was installed there via 'setup.py install
> --home=/usr/local'.  The problem is that python does NOT scan this directory
> for .pth files, even if it is listed in PYTHONPATH.  .pth files only have an
> effect for directories in sys.prefix, I think.

Debian uses the following patch to site.py to look in /usr/local also:

--- /usr/lib/python2.3/site.py  2004-05-13 15:55:47.000000000 -0400
+++ Lib/site.py 2004-03-30 20:46:01.000000000 -0500
@@ -161,10 +156,10 @@
     if reset:
         _dirs_in_sys_path = None
 
-prefixes = [os.path.join(sys.prefix, "local"), sys.prefix]
+prefixes = [sys.prefix]
 sitedir = None # make sure sitedir is initialized because of later 'del'
 if sys.exec_prefix != sys.prefix:

You can also make a sitecustomize.py that does the adding of the
various directories (it's imported at the end of site.py).

## sitecustomize.py
import site
site.addsitedir('/usr/local')

> I have actually come to HATE with a vengeance packages which rely on .pth files,
> because of this behavior of python of not including them for anything in
> PYTHONPATH.  So I would really appreciate pointers from someone who has
> successfully solved this, since it's quite likely that I'm just misusing the
> system.

Bleh, yes. .pth files are mostly a hack for packages that *should be*
actual Python packages.

-- 
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca



More information about the Python-list mailing list