在导入 swig 生成的包装器的模块中使用 matplotlib 进行绘图时,Python 崩溃

发布于 2024-08-25 03:56:59 字数 203 浏览 6 评论 0原文

我有一个 python 模块,它导入用 swig 生成的模块。当我稍后在该模块中尝试调用 matplotlib 的 show() 函数时,python 崩溃了,没有任何提示,出了什么问题。当我用 swig 生成的模块注释 import 语句时,一切正常。 有人知道这种行为的原因是什么吗?我知道这是一个非常不具体的问题表述。但是,我并不期望解决我的问题,只是提示我可以在哪里查找问题。 谢谢。

I have a python module that imports a module generated with swig. When I try to call the show() function of matplotlib later in that module, python crashes without any hint, what went wrong. When I comment the import statement with the swig generated module out, everything works fine.
Does anybody have a clue to what could be the reason for this behaviour? I'm aware that this is a very unspecific formulation of the problem. But, I don't expect a solution to my problem, just a hint to where I could look at to find the problem.
Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

疾风者 2024-09-01 03:56:59

我首先在 gdb 下运行脚本并查看堆栈跟踪。最新版本的 gdb 内置了对 python 调试的支持。

$ gdb python
(gdb) run /path/to/script.py
# wait for crash #
(gdb) bt
# stack trace here #

更多信息请参见此处

I'd start with running the script under gdb and looking at the stack trace. Recent versions of gdb have built in support for python debugging.

$ gdb python
(gdb) run /path/to/script.py
# wait for crash #
(gdb) bt
# stack trace here #

More information here.

油焖大侠 2024-09-01 03:56:59

我怀疑您调用figure.show而不是plt.show()

以下脚本崩溃:

import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111)

ax.plot([25, 43, 65], [3500, 5500, 5800])

fig.show() # use plt.show() instead

此脚本工作正常:

import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111)

ax.plot([25, 43, 65], [3500, 5500, 5800])

plt.show()

I suspect that you call figure.show instead of plt.show()

The following script crash:

import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111)

ax.plot([25, 43, 65], [3500, 5500, 5800])

fig.show() # use plt.show() instead

This script is working fine:

import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111)

ax.plot([25, 43, 65], [3500, 5500, 5800])

plt.show()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文