I'm trying to run a python script with ros2 in my docker container, and everything up to running the Script works, I can even run Gazebo via a launch file, and it works.
The Error ROS gives me is the following:
root@86d8bf3a6eb9:/# ros2 run field_robot robot_spawner.py
Traceback (most recent call last):
File "/opt/ros/foxy/bin/ros2", line 11, in <module>
load_entry_point('ros2cli==0.9.11', 'console_scripts', 'ros2')()
File "/opt/ros/foxy/lib/python3.8/site-packages/ros2cli/cli.py", line 67, in main
rc = extension.main(parser=parser, args=args)
File "/opt/ros/foxy/lib/python3.8/site-packages/ros2run/command/run.py", line 70, in main
return run_executable(path=path, argv=args.argv, prefix=prefix)
File "/opt/ros/foxy/lib/python3.8/site-packages/ros2run/api/__init__.py", line 61, in run_executable
process = subprocess.Popen(cmd)
File "/usr/lib/python3.8/subprocess.py", line 858, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.8/subprocess.py", line 1704, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/field_robot/dev_ws/install/field_robot/lib/field_robot/robot_spawner.py'
And yes, I checked, the File actually exists:
root@86d8bf3a6eb9:/# ls -l /field_robot/dev_ws/install/field_robot/lib/field_robot/robot_spawner.py
-rwxr-xr-x 1 root root 1964 Apr 12 14:37 /field_robot/dev_ws/install/field_robot/lib/field_robot/robot_spawner.py
Also, I'm running the Host system on Windows, so it could be that something with windows is fucked up, so if you have an Idea what could be the Problem there, that also might be it
CodePudding user response:
Based on the comments it appears you're running into this issue because of the file type. If they're being edited in Windows first it is likely they are DOS files and not UNIX files. I know this causes issues with ROS1 so I assume it's the case in ROS2 as well. To fix this, you have a couple of options.
Usually the easiest would be to use dos2unix
. This isn't installed by default but you can get it via apt install dos2unix
assuming your image is Ubuntu. The files can be converted by running dos2unix <filename>
inside your container.