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

Guido van Rossum guido@CNRI.Reston.VA.US
Wed, 01 Dec 1999 13:55:40 -0500


> I would like to argue that on Windows, import of dynamic libraries is
> broken.  If a file something.pyd is imported, then sys.path is searched
> to find the module.  If a file something.dll is imported, the same thing
> happens.  But Windows defines its own search order for *.dll files which
> Python ignores.  I would suggest that this is wrong for files named
> *.dll,
> but OK for files named *.pyd.

I think you misunderstand some of the issues.

Python cannot import every .dll file.  Only .dll files that conform to
the convention for Python extension modules can be imported.  (The
convention is that it must export an init<module> function.)

On most other platforms, shared libraries must have a specific
extension (e.g. .so on most Unix).  Python allows you to drop such a
file into any directory where is looks for modules, and it will then
direct the dynamic load support to load that specific file.

This seems logical -- Python extensions must live in directories that
Python searches (Python must do its own search because the search
order is significant).

On Windows, Python uses the same strategy.  The only modification is
that it is allowed to give the file a different extension, namely
.pyd, to indicate that this really is a Python extension and not a
regular DLL.  This was mostly introduced because it is apparently
common to have an existing DLL "foo.dll" and write a Python wrapper
for it that is also called "foo".  Clearly, two files foo.dll are too
confusing, so we let you name the wrapper foo.pyd.  But because the
file format is essentially that of a DLL, we don't *require* this
renaming; some ways of creating DLLs in the first place may make it
difficult to do.

> A SysAdmin should be able to install and maintain *.dll as she has
> been trained to do.  This makes maintaining Python installations
> simpler and more un-surprising.

I don't see that a SysAdmin needs to do much DLL management.  This is
up to installer scripts.  Anyway how hard can it be for a SysAdmin to
leave DLLs in specific directories alone?

> I have no solution to the backward compatibilty problem.  But the
> code is only a couple lines.  A LoadLibrary() call does its own
> path searching.

But at what point should this LoadLibrary() call be called?  The
import statement contains no clue that a DLL is requested -- the
sys.path search reveals that.

I claim that there is nothing with the current strategy.

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