SimType.SIM_PHYSX is 'isaacgym._bindings.linux-x86_64.gym_38.SimType' object
但是如果直接
from isaacgym._bindings.linux-x86_64.gym_38 import SimType
会报错:from isaacgym._bindings.linux-x86_64.gym_38 import SimType ^ SyntaxError: invalid syntax
因为模块路径不符合 Python 的语法规则。由于模块路径中包含了像 -
和 .
这样的特殊字符,这些字符通常不符合 Python 的命名规则,所以直接导入会导致语法错误。
使用 动态导入:
import importlib
# 使用 importlib 动态导入具有特殊字符的模块
module_name = 'isaacgym._bindings.linux-x86_64.gym_38'
isaacgym_module = importlib.import_module(module_name)
# 从模块中导入 SimType
SimType = getattr(isaacgym_module, 'SimType')
# 设置物理引擎为 PHYSX
physics_engine = SimType.SIM_PHYSX
# 使用 physics_engine 作为参数
create_sim(self, 0, 0, physics_engine, sim_params)