[Python-Dev] Re: .DLL vs .PYD search order
James C. Ahlstrom
Wed, 01 Dec 1999 15:36:04 -0500
David Ascher wrote:
> Why is the DLL search path superior?
> In my experience, the DLL search path (PATH for short) is problematic
> because it requires either using the System control panel or modifying
> autoexec.bat, both of which can have massive systemic effects completely
> unrelated to Python if a mistake is made during the modification.
I agree that altering PATH is problematic. So is altering PYTHONPATH
and for exactly the same reason. That is why I think PYTHONPATH is
a bad idea.
The reason the DLL search path is superior is that it is not just PATH.
It defines a path which includes the install directory of the
plus the system directories, and this path is discovered at runtime. So
it is not necessary to set a global PYTHONPATH, nor make registry
nor do anything at all. It Just Works.
The Windows DLL search path is:
1) The directory of the executable program. That means you can just
throw all your DLL's in with the *.exe's, and it all Just Works.
2) The current directory. Also useful.
3) The Windows system directory (call GetSystemDirectory() to get this).
4) The Windows directory (call GetWindowsDirectory() to get this).
These two directories are used for system files. Think of /sbin,
Windows apps usually throw some of their DLL's here, especially if
are of general interest.
5) The directories in PATH. This is relatively useless, and AFAIK it
is seldom used in a real installation. It is a left-over from DOS.
That is also why it appears last.
> On UNIX, the equivalent to Windows' PATH is typically LD_LIBRARY_PATH,
> although I think there are significant variations in how that works across
> platforms. Most beginning unix users have no idea how to modify their
> LD_LIBRARY_PATH, as they typically don't understand the configuration
> mechanisms on Unix (system vs. user-specific, login vs. shell-specific,
> different shell configuration languages, etc.).
> I know it's not what you had in mind, but have you tried doing something
> import sys, os, string
> sys.path.extend(string.split(os.environ['PATH'], ';'))
Adding PATH (or anything else) to PYTHONPATH is making it worse. Have
you tried "import sys; print sys.path" on Windows? It is junk.