[Python-Dev] Re: .DLL vs .PYD search order

Guido van Rossum guido@CNRI.Reston.VA.US
Wed, 01 Dec 1999 18:00:21 -0500


> Fredrik Lundh wrote:
> 
> > > you tried "import sys; print sys.path" on Windows?  It is junk.
> > 
> > not on my machine.
> 
> On my Windows machine I get:
> 
> ['', '.', 'N:/prd/winlease/vest', '.\\DLLs', '.\\lib',
>   '.\\lib\\plat-win', '.\\lib\\lib-tk', 'f:\\bin']
> 
> PYTHONPATH is N:/prd/winlease/vest.
> os.path.dirname(sys.executable) is F:/bin.
> The others are junk.  What do you get?  Did
> you change sys.path from the default?

You must not have used the standard Python installer; if you had used
it you wouldn't have had this problem (and perhaps we wouldn't have
had this discussion).

The problem is that you apparently have installed python.exe in
f:\bin.  "Modern" Python versions execute some code at startup that
comes up with a suitable value for sys.path; the Windows version of
this code is in PC/getpathp.c -- I recommend that you study it.  This
code tries to find the Python install directory by looking for a
"landmark" file relative to the executable path, and then adds a bunch
of directory entries to the path relative to the install directory.
If it fails, it defaults to "." for the install directory.  The
entries '.\\DLLs', '.\\lib', '.\\lib\\plat-win', '.\\lib\\lib-tk' are
all a result of this failing.

As long as this works, there is no need for the user (or anyone) to
ever set the PYTHONPATH variable -- that variable is only needed to
add directories in front of sys.path for stuff that getpathp.c doesn't
know about (e.g. PIL, Numeric, etc.).  With packagized versions of
those modules, even that won't be necessary, because the packages will
be dropped in the Python install directory (typically C:\Program
Files\Python).

I believe that most of your desire to get rid of PYTHONPATH comes from
your insistence to bypass the default installer.  There's probably a
way to install your app in such a way that the getpathp.c algorithm
actually succeeds?  There's also a separate env variable, PYTHONHOME,
which overrides the Python install directory; if getpathp.c sees that
it is set, it will bypass the search relative to the executable's
path.

I take blame for not documenting all this well enough.  However I wish
you stopped criticizing the design -- I think the design is quite
solid.

--Guido van Rossum (home page: http://www.python.org/~guido/)