Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/138.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何修复导入错误:导入时DLL加载失败\u hello:找不到指定的模块。使用SWIG时_Python_C++_Swig - Fatal编程技术网

Python 如何修复导入错误:导入时DLL加载失败\u hello:找不到指定的模块。使用SWIG时

Python 如何修复导入错误:导入时DLL加载失败\u hello:找不到指定的模块。使用SWIG时,python,c++,swig,Python,C++,Swig,我目前正在学习包装器的工作原理,并在Windows10上使用SWIG。我在C++中写了一个函数,我试图用Python调用它。在尝试导入python模块时,我遇到了错误 Traceback (most recent call last): File "C:\Users\mathw\Documents\projects\hello\hello.py", line 14, in swig_import_helper return importlib.import_mo

我目前正在学习包装器的工作原理,并在Windows10上使用SWIG。我在C++中写了一个函数,我试图用Python调用它。在尝试导入python模块时,我遇到了错误

 Traceback (most recent call last):
  File "C:\Users\mathw\Documents\projects\hello\hello.py", line 14, in swig_import_helper
    return importlib.import_module(mname)
  File "C:\Python392\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 565, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 1108, in create_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
ImportError: DLL load failed while importing _hello: The specified module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\mathw\Documents\projects\hello\hello.py", line 17, in <module>
    _hello = swig_import_helper()
  File "C:\Users\mathw\Documents\projects\hello\hello.py", line 16, in swig_import_helper
    return importlib.import_module('_hello')
  File "C:\Python392\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: DLL load failed while importing _hello: The specified module could not be found.
你好,我

%module hello

%{
extern int foo();
%}

extern int foo();
这些是我在命令提示符中调用的命令。这些命令基于此


使用这些命令后,我尝试导入hello,但出现了上述错误。

我觉得第三个编译命令有问题。在
\u hello.pyd
之前需要一个
-o
,所以它应该是
g++-shared hello.o hello\u wrap.o-o\u hello.pyd-lc:\Python392\libs-L python39
int foo();
%module hello

%{
extern int foo();
%}

extern int foo();
swig -c++ -python hello.i
g++ -c hello.cpp hello_wrap.cxx -I C:\Python392\include
g++ -shared hello.o hello_wrap.o _hello.pyd -L C:\Python392\libs -l python39