1414# along with this program. If not, see <https://www.gnu.org/licenses/>.
1515
1616
17+ import os
18+ import glob
19+ import subprocess
20+
1721from launch import LaunchDescription , LaunchContext
1822from launch .actions import DeclareLaunchArgument , OpaqueFunction
1923from launch .substitutions import LaunchConfiguration , PythonExpression
2024from launch_ros .actions import Node
2125from launch .conditions import IfCondition
26+ from ament_index_python .packages import get_package_share_directory
2227
2328
2429def generate_launch_description ():
@@ -28,6 +33,14 @@ def run_yolo(context: LaunchContext, use_tracking, use_3d):
2833 use_tracking = eval (context .perform_substitution (use_tracking ))
2934 use_3d = eval (context .perform_substitution (use_3d ))
3035
36+ share_dir = get_package_share_directory ("yolo_ros" )
37+ subprocess .run (["uv" , "sync" , "--project" , share_dir ], check = True )
38+ venv_site_pkgs = glob .glob (
39+ os .path .join (share_dir , ".venv" , "lib" , "python*" , "site-packages" )
40+ )
41+ existing_pythonpath = os .environ .get ("PYTHONPATH" , "" )
42+ new_pythonpath = ":" .join (venv_site_pkgs + [existing_pythonpath ]).strip (":" )
43+
3144 model_type = LaunchConfiguration ("model_type" )
3245 model_type_cmd = DeclareLaunchArgument (
3346 "model_type" ,
@@ -231,6 +244,7 @@ def run_yolo(context: LaunchContext, use_tracking, use_3d):
231244 executable = "yolo_node" ,
232245 name = "yolo_node" ,
233246 namespace = namespace ,
247+ additional_env = {"PYTHONPATH" : new_pythonpath },
234248 parameters = [
235249 {
236250 "model_type" : model_type ,
@@ -259,6 +273,7 @@ def run_yolo(context: LaunchContext, use_tracking, use_3d):
259273 executable = "tracking_node" ,
260274 name = "tracking_node" ,
261275 namespace = namespace ,
276+ additional_env = {"PYTHONPATH" : new_pythonpath },
262277 parameters = [{"tracker" : tracker , "image_reliability" : image_reliability }],
263278 remappings = [("image_raw" , input_image_topic )],
264279 condition = IfCondition (PythonExpression ([str (use_tracking )])),
@@ -269,6 +284,7 @@ def run_yolo(context: LaunchContext, use_tracking, use_3d):
269284 executable = "detect_3d_node" ,
270285 name = "detect_3d_node" ,
271286 namespace = namespace ,
287+ additional_env = {"PYTHONPATH" : new_pythonpath },
272288 parameters = [
273289 {
274290 "target_frame" : target_frame ,
@@ -290,6 +306,7 @@ def run_yolo(context: LaunchContext, use_tracking, use_3d):
290306 executable = "debug_node" ,
291307 name = "debug_node" ,
292308 namespace = namespace ,
309+ additional_env = {"PYTHONPATH" : new_pythonpath },
293310 parameters = [{"image_reliability" : image_reliability }],
294311 remappings = [
295312 ("image_raw" , input_image_topic ),
0 commit comments