From 3a68d3c675302f4e170cb24ea382cae9c3f33d2e Mon Sep 17 00:00:00 2001 From: Jack Kolb Date: Wed, 14 Aug 2024 17:08:58 -0400 Subject: [PATCH] Fixed simulator imports for local installs The Getting Started instructions (http://virtual-home.org/documentation/master/get_started/get_started.html) state to clone the repo and no other installation setup. However, in Python 3.12 (I am unsure about earlier versions) the imports in the Getting Started guide fail (ModuleNotFoundError). This commit wraps the __init__.py submodule imports in a try/catch that allows for importing virtualhome modules from parent folders. --- virtualhome/__init__.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/virtualhome/__init__.py b/virtualhome/__init__.py index 184ac266d..2fdf92a14 100644 --- a/virtualhome/__init__.py +++ b/virtualhome/__init__.py @@ -7,5 +7,12 @@ new_path = original_path + '/virtualhome/simulation' sys.path.append(new_path) -from unity_simulator.comm_unity import UnityCommunication -from unity_simulator import utils_viz \ No newline at end of file +# if installed via pip +try: + from unity_simulator.comm_unity import UnityCommunication + from unity_simulator import utils_viz + +# if running locally (cloned into the project repository) +except ModuleNotFoundError: + from .simulation.unity_simulator.comm_unity import UnityCommunication + from .simulation.unity_simulator import utils_viz