[python-win32] Trouble loading any DLL in embedded Python

Chris Phoenix cphoenix@best.com
Sat, 14 Sep 2002 12:25:32 -0500


I've embedded Python in an MFC application, linking to python21_d.lib
(Python version 2.1.3).  It appears to me that the embedded Python
interpreter is refusing even to look for modules with extension .pyd.  I
wrote a simple file, deffoo.py, and put it in a new 'c:/pytest'
directory.  It imported correctly in both IDLE and my program.  (I
deleted deffoo.pyc between each test.)

IDLE

>>> import sys
>>> sys.path.append('c:/pytest')
>>> import deffoo
>>> dir(deffoo)
['__builtins__', '__doc__', '__file__', '__name__', 'foo']
>>> 

Embedded, verbose mode on

import sys
sys.path.append('c:/pytest')
import deffoo
import deffoo # from c:/pytest\deffoo.py
# wrote c:/pytest\deffoo.pyc
dir(deffoo)
>>> ['__builtins__', '__doc__', '__file__', '__name__', 'foo']



Then I renamed it from deffoo.py to deffoo.pyd.  Here's what happened...

IDLE, renamed extension

>>> import sys
>>> sys.path.append('c:/pytest')
>>> import deffoo
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in ?
    import deffoo
ImportError: DLL load failed: A device attached to the system is not
functioning.
>>> 

Embedded, renamed extension

import sys
sys.path.append('c:/pytest')
import deffoo
Traceback (most recent call last):
  File "<string>", line 1, in ?
ImportError: No module named deffoo
  [ At this point I moved deffoo.pyc back from the recycle bin]
import deffoo
import deffoo # precompiled from c:/pytest\deffoo.pyc

So, it looks like the embedded version is simply not looking for files
ending in .pyd, though it will look for .pyc files in the same
directory.

How can I fix this?

Thanks,
Chris

--
Chris Phoenix cphoenix@best.com http://www.best.com/~cphoenix
Interests: nanotechnology, dyslexia, caving, filk, SF, patent
reform, stained glass, hang gliding