Python,从 Python/Blender 的发布版本加载调试模块
我一直在为 Blender 编写一个导出脚本,它使用 python 来处理任何插件。由于我的大部分代码库都是 C++ 语言,因此我决定将代码包装为 python 模块 (pyd),该模块将从导出脚本导入并传递所有相关位进行转换。
只要我让发布版本 Blender 加载模块就可以了,我什至可以使用 Visual Studio 进行调试 - 但为了解决错误,发布版本不可靠,所以我需要使用模块的调试版本。不幸的是,在这种情况下,模块不会加载。
从 python 控制台:
>>> import exporter_d
Traceback (most recent call last):
File "<blender_console>", line 1, in <module>
ImportError: DLL load failed: The specified module could not be found.
环顾四周后,我发现错误是找不到另一个 dll,并且由于我没有加载任何其他内容,所以我添加了 python 的调试版本以及我的模块。现在错误不同了:
Traceback (most recent call last):
File "<blender_console>", line 1, in <module>
ImportError: dynamic module does not define init function (PyInit_exporter_d)
所以我将模块初始化名称从“PyInit_exporter”更改为“PyInit_exporter_d”(并删除了调试 pythond.dll,因为它因致命错误而使搅拌机崩溃),这返回第一个错误(dll 加载失败)。
所以,我的问题是,在运行 python 的发布版本时,如何加载 python 模块的调试版本? 由于 python 嵌入在搅拌机中,我想避免下载源代码并重建它。
I have been writing a export script for Blender, which uses python for any addons. Since most of my codebase is in C++ I decided to wrap my code as a python module (pyd) which will be imported from the export script and pass all the relevant bits for conversion.
As long as I make release builds blender loads the module just fine and I can even debug with visual studio - but to resolve a bug, the release builds is not reliable so I need to use a debug build of the module. Unfortunately in that case the module doesnt load.
From python console:
>>> import exporter_d
Traceback (most recent call last):
File "<blender_console>", line 1, in <module>
ImportError: DLL load failed: The specified module could not be found.
After looking around for a bit, I find out that the error is that another dll couldnt be found and since I am not loading anything else I added the debug build of python along with my module. Now the error is different:
Traceback (most recent call last):
File "<blender_console>", line 1, in <module>
ImportError: dynamic module does not define init function (PyInit_exporter_d)
So I changed the module init name from "PyInit_exporter" to "PyInit_exporter_d" (and removed the debug pythond.dll since it was crashing blender with a fatal error) which returns the first error (dll load faild).
So, my question is this, how can I load debug builds of a python module when running a release version of python?
Since python is embedded in blender, I would like to avoid downloading the source and rebuilding it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是如何设置环境,以便您可以使用调试和发布构建:
在您的 C++ 代码中,您需要
在 Visual Studio 解决方案中(或任何您用来指定代码编译结果的名称)说
与
导入时,
python.exe 和 python_d.exe 一起使用
This is how to setup the environment so that you can use both debug and release build:
In your c++ code, you need to have
In your Visual Studio solution (or whatever you use to specify the name of the result of compilation of your code) say
and
When importing, use
with both python.exe and python_d.exe
我能够在 Python 扩展中的本机代码中进行调试:结合调试和发布 python 库:但我使用了一些技巧:
将/Ox更改为/Od
将 /Zi 标志添加到编译器标志
将 /DEBUG 标志添加到链接器标志
TODO:将这些更改集成到 Python distutils 中:为 Visual Studio 工具链添加“--build --relWithDebInfo”标志
I was able to get debugging working in native code in Python extension: with mix of debug and release python libs: but I used some hacks:
change /Ox to /Od
add /Zi flag to compiler flags
add /DEBUG flag to linker flags
TODO: integrate these changes into Python distutils: add a "--build --relWithDebInfo" flag for visual studio toolchain