In the past I have been able to launch my ros node from vs code and step through and debug it. For my rosjec enviroment I can’t seem to be able to. I get the following error.
user:~$ cd '/home/user' && env '/bin/python3' '/home/theia/plugins/vscode-python/extension/pythonFiles/lib/python/debugpy/launcher' '32785' '--' '/home/user/ros2_ws/src/wall_follower/wall_follower/wall_following.py'
Traceback (most recent call last):
File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/home/theia/plugins/vscode-python/extension/pythonFiles/lib/python/debugpy/__main__.py", line 45, in <module>
cli.main()
File "/home/theia/plugins/vscode-python/extension/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 430, in main
run()
File "/home/theia/plugins/vscode-python/extension/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 267, in run_file
runpy.run_path(options.target, run_name=compat.force_str("__main__"))
File "/usr/lib/python3.8/runpy.py", line 265, in run_path
return _run_module_code(code, init_globals, run_name,
File "/usr/lib/python3.8/runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/home/user/ros2_ws/src/wall_follower/wall_follower/wall_following.py", line 76, in <module>
main()
File "/home/user/ros2_ws/src/wall_follower/wall_follower/wall_following.py", line 64, in main
rclpy.init(args=args)
File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/__init__.py", line 71, in init
return context.init(args)
File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/context.py", line 64, in init
rclpy_implementation.rclpy_logging_configure(capsule)
_rclpy.RCLError: Failed to initialize logging: Failed to create log directory: /home/user/.ros/log, at /tmp/binarydeb/ros-foxy-rcl-logging-spdlog-1.1.0/src/rcl_logging_spdlog.cpp:100
user:~$
I am able to run the node normally if I launch it with python from the command line and it works as expected. Also I tried to source the environment where the debug terminal is but that doesn’t seem to help. Online on a similarish issue it mentions that you should do the following: remove --user or add --home to your docker arguments. In a similar vein it looks like the command is targeting the /home/theia/ directory for the user and not the user directory so I’m not sure if that is the issue.
Has anyone else been able to debug a python script using ROS2 in a rosject? Thanks.