From 6e626c0dc16c195d6f8f3302c75c4276a2d3c815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Aumu=CC=88ller?= Date: Fri, 9 Dec 2022 15:54:45 +0100 Subject: [PATCH] Revert "Revert "Replaced deprecated "load_module" with "exec_module""" This reverts commit 59c501023ca6b58131ff7292358824545e357b6d. https://github.com/pybind/pybind11/pull/3798#issuecomment-1072699131 gives the cause for the real problem --- lib/vistle/python/pythonmodule.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/vistle/python/pythonmodule.cpp b/lib/vistle/python/pythonmodule.cpp index cb3ad7588..63f89aa94 100644 --- a/lib/vistle/python/pythonmodule.cpp +++ b/lib/vistle/python/pythonmodule.cpp @@ -1592,11 +1592,14 @@ bool PythonModule::import(py::object *ns, const std::string &path) std::cerr << "Python: loading " << path + "/vistle.py" << std::endl; #if PY_MAJOR_VERSION > 3 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 6) py::eval(R"( + import sys import importlib import importlib.util spec = importlib.util.spec_from_file_location(modulename, path) if spec != None and spec.loader != None: - newmodule = spec.loader.load_module() + newmodule = importlib.util.module_from_spec(spec) + sys.modules[modulename] = newmodule + spec.loader.exec_module(newmodule) )", *ns, locals); #else