2016-10-03 4 views
1

나는 꿀꺽 꿀꺽 튜토리얼을 따라하기 위해 노력하고있어하지만 난 지금 내가 사용하고, 붙어있어 :꿀꺽 꿀꺽 튜토리얼 문제

  • 파이썬 3.5.1 (v3.5.1을 1시 54분 25초) MSC v.1900 64 비트 (AMD64)]는 Win32에
  • Vs2015 64 마이크로 소프트 (R) C/C++ 컴파일러 최적화 버전 19.00.23918 64 대
  • SWIG 버전 3.0.10

내용물은 다음과 같습니다.

example.c

#include <time.h> 
double My_variable = 3.0; 

int fact(int n) { 
    if (n <= 1) return 1; 
    else return n*fact(n-1); 
} 

int my_mod(int x, int y) { 
    return (x%y); 
} 

char *get_time() 
{ 
    time_t ltime; 
    time(&ltime); 
    return ctime(&ltime); 
} 

본보기 그런

%module example 
%{ 
/* Put header files here or function declarations like below */ 
extern double My_variable; 
extern int fact(int n); 
extern int my_mod(int x, int y); 
extern char *get_time(); 
%} 

extern double My_variable; 
extern int fact(int n); 
extern int my_mod(int x, int y); 
extern char *get_time(); 

내가 할 :

  • swig -python example.i
  • cl /D_USRDLL /D_WINDLL example.c example_wrap.c -Ic:\Python351\include /link /DLL /out:example.pyd /libpath:c:\python351\libs python35.lib
  • 내가 python -c "import example"을하려고 할 때 53,691,363,210

는하지만 얻을 :

Traceback (most recent call last): 
    File "<string>", line 1, in <module> 
ImportError: dynamic module does not define module export function (PyInit_example) 

질문에 가서 무엇을 내가 그것을 어떻게 수정합니까?

답변

1

SWIG에 대한 동적 연결 모듈의 이름은 밑줄로 시작해야하며,이 경우 _example.pyd입니다.

from sys import version_info 
if version_info >= (2, 6, 0): 
    def swig_import_helper(): 
     from os.path import dirname 
     import imp 
     fp = None 
     try:           # ↓ SEE HERE 
      fp, pathname, description = imp.find_module('_example', [dirname(__file__)]) 
     except ImportError: 
      import _example # ← AND HERE 
      return _example # ← AND HERE 
     if fp is not None: 
      try:      # ↓ AND HERE 
       _mod = imp.load_module('_example', fp, pathname, description) 
      finally: 
       fp.close() 
      return _mod 
    _example = swig_import_helper() # ← AND HERE 
    del swig_import_helper 
else: # ↓ AND HERE 
    import _example 

그것은 사실 SWIG 래핑 된 C++ 모듈의 이름입니다 꿀꺽 꿀꺽 생성 된 파이썬 파일이 _example라는 이름의 모듈을 찾고, 해당 파일의 시작을 참조하십시오.