c++中嵌入式python的Matplotlib和子解释器
Matplotlib and subinterpreter for embedded python in c++
我刚刚在我的c++嵌入式python编辑器中添加了子解释器,以便每次执行都有一个干净的解释器。
PyThreadState* tmpstate = Py_NewInterpreter();
PyThreadState_Swap(tmpstate);
... run the script ...
Py_EndInterpreter(tmpstate);
我自己的模块正在工作,我测试numpy没有任何问题。问题在于matplotlib
如果我第一次运行,一切看起来都很好。第二次我得到:
<class 'TypeError'>: attribute of type 'NoneType' is not callable: File "<string>", line 1, in <module>
File "C:Python33libsite-packagespylab.py", line 1, in <module>
from matplotlib.pylab import *
File "C:Python33libsite-packagesmatplotlib__init__.py", line 152, in <module>
from matplotlib.rcsetup import (defaultParams,
File "C:Python33libsite-packagesmatplotlibrcsetup.py", line 19, in <module>
from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
File "C:Python33libsite-packagesmatplotlibfontconfig_pattern.py", line 25, in <module>
from matplotlib.pyparsing_py3 import Literal, ZeroOrMore,
File "C:Python33libsite-packagesmatplotlibpyparsing_py3.py", line 3275, in <module>
_escapedHexChar = Combine( Suppress(_bslash + "0x") + Word(hexnums) ).setParseAction(lambda s,l,t:unichr(int(t[0],16)))
File "C:Python33libsite-packagesmatplotlibpyparsing_py3.py", line 2961, in __init__
self.leaveWhitespace()
File "C:Python33libsite-packagesmatplotlibpyparsing_py3.py", line 2587, in leaveWhitespace
self.expr = self.expr.copy()
File "C:Python33libsite-packagesmatplotlibpyparsing_py3.py", line 705, in copy
cpy = copy.copy( self )
File "C:Python33libcopy.py", line 89, in copy
rv = reductor(2)
这似乎是Python 3.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.
相关文章:
- 文件格式的编写解释器(C++ Arduino)
- 从嵌入式解释器捕获 python 窗口输出C++
- 错误,在嵌入在C++程序中的 python 脚本中使用 matplotlib 时
- 如何为 tflite 解释器调用 Flex 委托?
- 在解释器开发期间解析令牌问题
- 在C 11 printf格式上寻求解释器,这些printf格式会消耗多个值
- Brainfuck解释器奇怪的输出
- AOSP中的SH解释器源代码在哪里
- 是否有用于C++的类似 C 的语法脚本语言解释器?
- 在C++中嵌入 Python:解释器在执行过程中的持久性
- 脑解释器在C++产生不正确的结果
- 如何中断嵌入C++应用程序中的python解释器
- 无法让 matplotlib 事件处理程序与 Boost.Python 一起工作
- Matplotlib - 找不到 Numpy 头文件
- 解释器和中介器的设计模式有什么区别
- 使用 Python 的 Matplotlib 绘制C++程序中生成的数据
- 嵌入式C++解释器,用于在编译程序中操作数据
- Matplotlib 从 c++ 绘制多个图表
- 使用自定义模块构建 python 解释器时出现问题
- c++中嵌入式python的Matplotlib和子解释器