c语言中嵌入式python的Matplotlib和子解释器++

2024-09-26 22:54:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我只是在我的c++嵌入式python编辑器中添加了子解释器,这样每次执行都有一个干净的解释器。在

  PyThreadState* tmpstate = Py_NewInterpreter();
  PyThreadState_Swap(tmpstate);
  ... run the script ...
  Py_EndInterpreter(tmpstate);

我自己的模块正在工作,我测试了numpy没有任何问题。问题在于matplotlib

如果我第一次运行的话一切都很好。第二次我得到:

^{pr2}$

Tags: 模块therunpynumpymatplotlibscript编辑器
1条回答
网友
1楼 · 发布于 2024-09-26 22:54:24

这似乎是Python3.3中的一个错误:http://bugs.python.org/issue17408

问题是:

The reason is in Objects/typeobject.c: import_copyreg() has a static cache of the copyreg      module.
When the interpreter stops, the module is filled with None... but gets reused in the next     instance.

Resetting this "mod_copyreg" variable to NULL fixes the issue.
pickle is also broken for the same reason.

相关问题 更多 >

    热门问题