[Errno 20] Not a directory while running python scripts under ament_cmake compiler

Greetings,

Now I am in the Unit 3: TF Broadcasting and Listening.

In the example 3.2.1, I follow the steps and compile successfully.

Here is the image about script “cam_bot_odom_to_tf_pub.py” after compling with ament_cmake:

image

Next, I run the script with the command below:

$ ros2 run my_tf_ros2_course_pkg cam_bot_odom_to_tf_pub.py

But get the error below:

Traceback (most recent call last):
  File "/opt/ros/galactic/bin/ros2", line 11, in <module>
    load_entry_point('ros2cli==0.13.1', 'console_scripts', 'ros2')()
  File "/opt/ros/galactic/lib/python3.8/site-packages/ros2cli/cli.py", line 67, in main
    rc = extension.main(parser=parser, args=args)
  File "/opt/ros/galactic/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/galactic/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)
NotADirectoryError: [Errno 20] Not a directory: '/home/user/ros2_ws/install/my_tf_ros2_course_pkg/lib/my_tf_ros2_course_pkg/cam_bot_odom_to_tf_pub.py'

How can I solve the error? Thanks.

Hello @kjoelovelife,

does this issue persist? Could you please post the contents of your CMakeLists.txt file, I will see if I can reproduce the error to help you.

Regards,

Roberto

Yes, now I still have the issue.
Here is the contents of CMakeLists.txt

cmake_minimum_required(VERSION 3.8)
project(my_tf_ros2_course_pkg)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(nav_msgs REQUIRED)
find_package(rclpy REQUIRED)

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  # the following line skips the linter which checks for copyrights
  # uncomment the line when a copyright and license is not present in all source files
  #set(ament_cmake_copyright_FOUND TRUE)
  # the following line skips cpplint (only works in a git repo)
  # uncomment the line when this package is not in a git repo
  #set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

# install
install(
	DIRECTORY launch
	DESTINATION share/${PROJECT_NAME}/
)


install(PROGRAMS
	scripts/cam_bot_odom_to_tf_pub.py
	DESTINATION lib/${PROJECT_NAME}/
)



ament_package()

Hello @kjoelovelife,

There are a few things to try out.

From your screenshot it seems the script exists in that location. Also verify the script is executable by running this command:

ls /home/user/ros2_ws/install/my_tf_ros2_course_pkg/lib/my_tf_ros2_course_pkg/

An executable script will be displayed in green color.

Also try using the ros2 run command without the .py extension and see if that works, like this:

ros2 run my_tf_ros2_course_pkg cam_bot_odom_to_tf_pub

If non of this works a different approach is to remove the package and start all over again. This is because there might be that a step was missing during the package creation process. Normally creating a package again is not a viable option, but in this particular case since the package only contains one script that is provided to you it might be the fastest way to get it running.

Let me now how it goes,

Cheers,

Roberto

Hi @rzegers,

I had verify the script is executable:

Also, I rebuild the packages base on deleting folders “log”, “install” and “build”.

Unfortunately, the erorr still exists.

Now my solution to finish the course is making “ament_python” package to complete.

Did you solve it by creating ament_python?

#! /usr/bin/env python3 is not a comment. Must be included.