Swig no module named _example

I can not reproduce the basic SWIG example on windows. My mistake is indicated in the SWIG docs, and I am sure that I am making 2 corrections that they mention. For this error:

>>> import example
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "example.py", line 2, in ?
    import _example
ImportError: No module named _example

The SWIG documentation clearly states:

forget about the underscore (_).

forget about the underscore (_). > If you receive this message, it means that

you either forgot to compile the shell code into an extension module or you did not give the extension enter the correct name. Make sure you compile the wrappers in a module called example.so. And don't forget the front underscore (). forget the main underscore (_).

, , : "_example", "_example.so", "example.dll", "example.so", "example.dll", "example.py" , , python , ().

:

//example.h
int foo_sum(int a, int b);

.

//example.cpp
int foo_sum(int a, int b) {
    return a + b;
}

.

//example.i
%module example
%{
#include "example.h"
%}

#include "example.h

:

gcc -IV:\temp\example\external\include\Python -O3 -Wall -c -fmessage-length=0 -oexample_wrap.o ..\example_wrap.c
g++ -IV:\temp\example\external\include\Python -O3 -Wall -c -fmessage-length=0 -oexample.o ..\example.cpp
g++ -LV:\temp\example\external\lib -shared -oexample.dll example_wrap.o example.o -lpython26

-O3, ( Release)

:

>>> import sys
>>> sys.path.append("/your/module/path")
>>> import example

EDIT:

, dll, "_example.pyd", "foo_sum"

EDIT: , extern "C" .i

+5
3

*.pyd. , .

+2

, , ++ .dll .pyd . , . , python, extern "C", . . , , Py_value, python.

0

I found that (in windows), if you create a dll, you need to call it _modulename.pyd This library (_modulename.pyd), the C ++ source module myapp.dll and the resulting modulename.py file must be in the path, as well as pythonxx .exe

0
source

All Articles