From 5405c4372f1dfa417ec90b2fcb3e155a28ffac64 Mon Sep 17 00:00:00 2001 From: YouJiacheng <1503679330@qq.com> Date: Tue, 23 Aug 2022 03:13:45 +0800 Subject: [PATCH] Replace deprecated `load_module` by `exec_module` `load_module` is deprecated since python 3.6. New implementation is based on https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly --- mujoco_py/builder.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mujoco_py/builder.py b/mujoco_py/builder.py index 5280b2c3..d24fc0a2 100644 --- a/mujoco_py/builder.py +++ b/mujoco_py/builder.py @@ -7,7 +7,7 @@ from distutils.core import Extension from distutils.dist import Distribution from distutils.sysconfig import customize_compiler -from importlib.machinery import ExtensionFileLoader +from importlib.util import module_from_spec, spec_from_file_location from os.path import abspath, dirname, exists, join, getmtime from random import choice from shutil import move @@ -126,8 +126,11 @@ def _ensure_set_env_var(var_name, lib_path): def load_dynamic_ext(name, path): """ Load compiled shared object and return as python module. """ - loader = ExtensionFileLoader(name, path) - return loader.load_module() + spec = spec_from_file_location(name, path) + module = module_from_spec(spec) + sys.modules[name] = module + spec.loader.exec_module(module) + return module class custom_build_ext(build_ext):