How do packages and .pth files work under Windows (Py 2.0)

Grzegorz Makarewicz mak at mikroplan.com.pl
Tue Dec 5 19:32:48 EST 2000


Create somename.pth in python root, eg.:
c:\blach
d:\blach

execute python and you will find c:\blach and d:\blach appended to sys.path

For more information look into lib/site.py:
def addsitedir(sitedir):
    ...
    for name in names:
        if name[-4:] == ".pth":
            addpackage(sitedir, name)

and code from global scope executed after addpackage:

prefixes = [sys.prefix]
if sys.exec_prefix != sys.prefix:
    prefixes.append(sys.exec_prefix)
for prefix in prefixes:
    if prefix:
       ...
       addsitedir(...)

mak


> -----Original Message-----
> From: python-list-admin at python.org
> [mailto:python-list-admin at python.org]On Behalf Of Jonathan Gilligan
> Sent: Tuesday, December 05, 2000 9:46 PM
> To: python-list at python.org
> Subject: Re: How do packages and .pth files work under Windows (Py 2.0)
> 
> 
> Thanks, but this doesn't tell me about when python reads .pth files,
> which is the crux of my problem. Between this and writing a
> __init__.py file which properly initializes the variable __all__, I
> managed to work around my immediate problem.
> 
> I have managed to resolve another part of my problem---it seems that
> Python reads the default value of the registry key
> "HKLM\Software\Python\CurrentVersion\2.0\PythonPath" only if it cannot
> resolve PYTHONHOME. If it can resolve PYTHONHOME, then it ignores the
> default value in "HKLM\Software\Python\CurrentVersion\2.0\PythonPath"
> and substitutes some default directories instead for the PYTHONPATH.
> It does add any values in keys below PythonPath, but not the value at
> the top of the tree.
> 
> This is undocumented, but can be found in the C code in getpathp.c.
> 
> I'd still like to know how to use .pth files properly, though, if
> anyone can help.
> 
> Jonathan
> 
> "Stuart" <sgm103 at cs.york.ac.uk> wrote in message
> news:z26X5.15943$R77.1248181 at nnrp4.clara.net...
> > > It would help me enormously if there were a way to get Python to
> print
> > > out a list of where it looks when it tries to resolve an "import".
> Is
> > > this possible?
> >
> > I'm not certain, but i think this does the trick:
> >
> > import sys
> > print sys.path
> 
> 
> 
> -- 
> http://www.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list