Repository navigation
Conversation
The docs say to cd into an example directory and run `python <script>.py`. These examples import `utils`, `Mapping` or `PathPlanning` from the repository root without adding it to sys.path, so they stop with ModuleNotFoundError before the simulation starts: - ArmNavigation two_joint_arm_to_point_control - Mapping ndt_map and normal_vector_estimation - PathPlanning ClosedLoopRRTStar (closed_loop_rrt_star_car, pure_pursuit, unicycle_model) and ModelPredictiveTrajectoryGenerator (trajectory_generator, lookup_table_generator) - PathPlanning TimeBasedPathPlanning (GridWithDynamicObstacles, PriorityBasedPlanner, SafeInterval, SpaceTimeAStar) - SLAM EKFSLAM, FastSLAM1 and FastSLAM2 Add the root to sys.path before those imports, as AtsushiSakai#1188 did for the PathTracking examples. The new test loads each script in a fresh interpreter from the script's directory, without the root on sys.path.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reference issue
Same problem as #966, #750 and #709. The latest comment on #750 (March 2026) still hits it with
SLAM/FastSLAM2/fast_slam2.py.What does this implement/fix?
"How to run sample codes" says to
cdinto an example directory and runpython <script>.py. These examples importutils,MappingorPathPlanningfrom the repository root without adding the root tosys.path, so they stop withModuleNotFoundErrorbefore anything runs:ArmNavigation/two_joint_arm_to_point_control/two_joint_arm_to_point_control.pyMapping/ndt_map/ndt_map.py,Mapping/normal_vector_estimation/normal_vector_estimation.pyPathPlanning/ClosedLoopRRTStar/(closed_loop_rrt_star_car.py,pure_pursuit.py,unicycle_model.py)PathPlanning/ModelPredictiveTrajectoryGenerator/(trajectory_generator.py,lookup_table_generator.py)PathPlanning/TimeBasedPathPlanning/(GridWithDynamicObstacles.py,PriorityBasedPlanner.py,SafeInterval.py,SpaceTimeAStar.py)SLAM/EKFSLAM/ekf_slam.py,SLAM/FastSLAM1/fast_slam1.py,SLAM/FastSLAM2/fast_slam2.pyThis adds
sys.path.append(str(pathlib.Path(__file__).parent.parent.parent))before those imports, the same fix #1188 made for the PathTracking examples. Forunicycle_model.pyandmotion_model.pythe line goes in the module itself, so every script that imports them works.The unit tests didn't catch this because
tests/conftest.pyputs the root onsys.path.Additional information
tests/test_run_from_script_directory.pyloads each of the scripts above in a fresh interpreter, with the script's directory as the working directory and without the root onsys.path. It usesrunpy.run_path, so only the imports run, not the simulations. All 15 cases fail on master and pass with this change.I found these by running every example the way the docs describe, from its own directory. After this change all of the scripts above get past their imports.
ndt_map.pythen stops with the separate #991 bug ('NDTMap' object has no attribute 'grid_map'), which this PR doesn't touch.Ran on Windows 11, Python 3.13 with the pinned requirements (
ecosleft out, it has no Windows wheel for 3.13):pytest tests/test_run_from_script_directory.py -Werror: 15 passed (15 failed with the source changes reverted)test_codestyle.pyandtest_mypy_type_check.py: passedCheckList