Extension module import error with MinGW, SWIG, and distutils

Phil Schmidt pschmidt at omnimn.com
Fri Aug 2 15:12:02 CEST 2002


I've been slaving away (ok, not quite, but my head is about ready to
burst!) trying to create an extension module on a Win2K machine, using
MinGW, SWIG, and distutils. I've been working with a very simple
example, just for the sake of learning the ropes, and I am now to the
point where, when I attempt to import my extension module, I get the
following traceback:

>>> import MyDemo
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in ?
    import MyDemo
ImportError: DLL load failed: The specified module could not be found.


Here's a summary of the steps I followed to create the MyDemo module:

1) I manually ran SWIG to create the wrapper file (because if I let
distutils call SWIG, it overwrites my C source file (and yes, I saw
the posts about that, so I need to update my distutils...))

2) I then run distutils, which, except for a couple mild warnings
about some SWIG functions being defined but not used, runs without
errors and creates a MyDemo.pyd file.

3) I copy the .pyd file to my Python22/DLLs directory, then try to use
it and get the error described above.

4) I ran the depends.exe utility on my .pyd file, and it says that the
"WINNTSYSTEM32PYTHON22.DLL" file is missing. The full path reported
for this file is
"c:\gnu_demo\simpledemo\build\lib.win32-2.2\WINNTSYSTEM32PYTHON22.DLL".
Of course, this is incorrect, but I don't know how to fix it.

5) As a test, I copied/renamed python22.dll to the path reported in
step (4), and tried again, with the same DLL load error.

So, now I'm stumped (and frustrated)! It appears from the posts here
that it is possible to make this work, but somehow I'm missing
something.

I would be grateful if anyone could offer any suggestions!

Here are the files I'm working with right now:

## demo.c ##
---------------------------------
int MyDemo(int x)
	{
	return x*(1-x);
	}



## demo.h ##
---------------------------------
int MyDemo(int x);



## demo.i ##
---------------------------------
/* File : example.i */
%module MyDemo

%{
#include "demo.h"
%}

int MyDemo(int x);


## setup.py ##
---------------------------------
from distutils.core import setup, Extension

setup (name = "MyDemo",
       version = "0.1",
       description = "A Test!",
       author = "Phil Schmidt",
       author_email = "pschmidt at omnimn.com",
       ext_modules = [Extension("MyDemo", ["demo.c", "demo_wrap.c"])]
      )



More information about the Python-list mailing list