开源改变世界

python3: axis: ImportError: ‘interpreter’ 不是内置模块 #825

推推 grbl 2年前 (2023-01-30) 153次浏览
关闭
dwrobel 打开了这个问题 2020 年 5 月 3 日 · 8条评论
关闭

python3: axis: ImportError: ‘interpreter’ 不是内置模块#825

dwrobel 打开了这个问题 2020 年 5 月 3 日 · 8条评论

注释

python3: axis: ImportError: 'interpreter' 不是内置模块 #825
贡献者

axis在python3 (3.7.7) 上运行Fedora 31生成 ImportError: 'interpreter' is not a built-in module如下:

$ linuxcnc
LINUXCNC - 2.9.0~pre0
Machine configuration directory is '/home/sw/linuxcnc/configs/my-simulated-mill'
Machine configuration file is 'my-simulated-mill.ini'
Starting LinuxCNC...
Found file(REL): ./my-simulated-mill.hal
Note: Using POSIX non-realtime
Found file(REL): ./custom.hal
note: MAXV     max: 25.000 units/sec 1500.000 units/min
note: LJOG     max: 25.000 units/sec 1500.000 units/min
note: LJOG default: 2.500 units/sec 150.000 units/min
note: jog_order='XYZ'
note: jog_invert=set()
/home/sw/projects/linuxcnc/bin/axis:3768: DeprecationWarning: tostring() is deprecated. Use tobytes() instead.
  glnav.use_pango_font(coordinate_font, 0, 128)
PYTHON: exception during 'this' export:
ImportError: 'interpreter' is not a built-in module

有趣的是,这不是致命错误,因为我可以成功进行“Linuxcnc”测试。

python3: axis: ImportError: 'interpreter' 不是内置模块 #825 rene-dev 添加了 蟒蛇3 标签 2020 年 5 月 3 日
python3: axis: ImportError: 'interpreter' 不是内置模块 #825
合作者

我也注意到了这条消息,但不知道它来自哪里,也不知道它对什么有影响。
一些测试使用解释器模块,它们似乎工作正常。

python3: axis: ImportError: 'interpreter' 不是内置模块 #825
贾拉马 评论了 2020 年 7 月 13 日  

当 Py_IsInitialized() == 1(例如 python 脚本中的“导入 gcode”)时会发生这种情况,因此 PyImport_ExtendInittab() 什么都不做,并且“解释器”模块未注册。

python3: axis: ImportError: 'interpreter' 不是内置模块 #825
贡献者

在我松开它之前把它写下来,这里是例外:

Error ( PYTHON: exception during ‘this’ export: \n %s \n ,exception_msg.c_str ( ));

 

python3: axis: ImportError: 'interpreter' 不是内置模块 #825
贡献者
萨蒂瓦达赫 评论了 2021 年 1 月 15 日  

就是这样!这个 try catch 在 python3 中是完全多余的,模块实际上是在这里导入的:

bp::object module = bp::import ( __main__ );

所以另一个应该可以用 python3 的 ifdef 删除。 

运行测试和合并请求将被提出

python3: axis: ImportError: 'interpreter' 不是内置模块 #825
贾拉马 评论了 2021 年 1 月 15 日  

这不是问题。在 Python3PyImport_ExtendInittab中,如果解释器已经初始化,则不会执行任何操作。然后gcode模块无法导入interpreter模块,因为它没有注册为内置。

相反,当Py_IsInitialized() == 1, 内置模块需要手动添加到PyImport_GetModuleDict(). 是这样的:

PythonPlugin::PythonPlugin(struct _inittab *inittab)
    : status(0)
    , module_mtime(0)
    , reload_on_change(0)
    , toplevel(0)
    , abs_path(0)
    , log_level(0)
{
	if (abs_path) {
		wchar_t *program = Py_DecodeLocale(abs_path, NULL);
		Py_SetProgramName(program);
	}

	if (inittab != NULL) {
		if (!Py_IsInitialized()) {
			if (PyImport_ExtendInittab(inittab) != 0) {
				logPP(-1, "cannot extend inittab");
				status = PLUGIN_INITTAB_FAILED;
				return;
			}
		} else {
			PyObject *sys_modules = PyImport_GetModuleDict(); // borrowed

			for (int i = 0; inittab[i].name != NULL; i++) {
				struct _inittab tab = inittab[i];
				PyObject *module = tab.initfunc();
				if (module == NULL) {
					logPP(-1, "failed to initialize built-in module '%s'", tab.name);
					status = PLUGIN_INITTAB_FAILED;
					return;
				}

				PyImport_AddModule(tab.name); // borrowed
				PyDict_SetItemString(sys_modules, tab.name, module);
				Py_DECREF(module);
			}
		}
	}

	Py_UnbufferedStdioFlag = 1;
	Py_Initialize();
	initialize();
}
python3: axis: ImportError: 'interpreter' 不是内置模块 #825
贡献者

你是对的,你的代码不需要编辑就可以工作!

python3: axis: ImportError: 'interpreter' 不是内置模块 #825
合作者

由#1042修复