C++ Swig Python(C 中的嵌入式 Python)在发布中有效,但在调试中无效
平台:Windows 7,64位(x64),Visual Studio 2008
我选择了Python& Swig 绑定作为应用程序的脚本环境。
作为原型,使用 main() 创建了一个简单的 VS 解决方案,该解决方案初始化 Python(Py_Initalize、Py_setPyHome 等)&执行test.py。在同一个解决方案中创建了另一个项目,它是一个简单类的 DLL。使用 SWIG 来包装此类。该 DLL 是 _MyClasses.pyd。 test.py 创建我的类的对象 &调用其成员函数。
所有这些在发布模式下都非常有效。但在调试模式下不起作用(甚至尝试用头敲笔记本电脑;-))。
我的工作输出如下所示(在发布和调试中):
x64
-debug
- _MyClasses.pyd
- MyClasses.py
- test.exe
- test.py
- python26.dll
- python26_d.dll
请注意,调试版本与 python26_d.lib 链接。为此必须自己构建 python!
test.py
import MyClasses
print "ello"
m = MyClasses.Male("John Doe", 25)
print m.getType()
Male是C++类。
The problem:
Traceback (most recent call last):
File "test.py", line 6, in <module>
import MyClasses
File "...\x64\Debug\MyClasses.py", line 25, in <module>
_MyClasses = swig_import_helper()
File "...\x64\Debug\MyClasses.py", line 17, in swig_imp
ort_helper
import _MyClasses
ImportError: No module named _MyClasses
[15454 refs]
我习惯了 Makefiles &我是 Visual Studio 新手。我不知道罪魁祸首是谁:Swig、Python 的调试版本、Visual Studio,我的愚蠢。
先感谢您。这将是一个很大的帮助。
Platform: Windows 7, 64 bit (x64), Visual Studio 2008
I chose Python & Swig binding as the scripting environment of the application.
As a prototype, created a simple VS solution with main() which initializes Python (Py_Initalize, Py_setPyHome, etc) & executes test.py. In the same solution created another project which is a DLL of a simple class. Used SWIG to wrap this class. This DLL is the _MyClasses.pyd. test.py creates the objects of my class & calls its member functions.
All this works like a charm in the Release mode. But does not work in Debug mode (even tried banging my head on the laptop ;-) ).
Output of my work looks like this (in both release & debug):
x64
-debug
- _MyClasses.pyd
- MyClasses.py
- test.exe
- test.py
- python26.dll
- python26_d.dll
Note that the debug version is linked against python26_d.lib. Had to build python myself for this!
test.py
import MyClasses
print "ello"
m = MyClasses.Male("John Doe", 25)
print m.getType()
Male is the C++ class.
The problem:
Traceback (most recent call last):
File "test.py", line 6, in <module>
import MyClasses
File "...\x64\Debug\MyClasses.py", line 25, in <module>
_MyClasses = swig_import_helper()
File "...\x64\Debug\MyClasses.py", line 17, in swig_imp
ort_helper
import _MyClasses
ImportError: No module named _MyClasses
[15454 refs]
I am used to Makefiles & am new to Visual Studio. I dont know who the culprit is here: Swig, The debug build of Python, Visual Studio, my stupidity.
Thank you in advance. It will be a great help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧——找到了。调试输出 dll 必须命名为 xxx_d.pyd!在上面的情况下它将是 _MyClasses_d.pyd
Alright - found it. The debug output dll has to be named xxx_d.pyd!! In above case it would be _MyClasses_d.pyd