ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

how to install a python file with ament_cmake

asked 2020-10-17 09:55:32 -0600

updated 2020-10-17 10:33:25 -0600

I have an ament_cmake package that is mostly c++ but it also contains a python script in the "package_dir/script" folder (following the ROS1 directory convention). My expectation is that the script could be invoked using "ros2 run" and also could be referenced from launch files as an executable node.

Would it be possible to install this python file as an executable script from this ament_cmake package? If that is possible, what would be the cmake "install" function I should use for the python file or the scripts directory?

Should I instead create another separated ament_python package for that single script?

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
2

answered 2020-10-17 18:24:13 -0600

This is the solution I found for that issue:

install(PROGRAMS
        scripts/myscript.py
        DESTINATION lib/${PROJECT_NAME})
edit flag offensive delete link more
0

answered 2022-02-12 19:37:24 -0600

guru_florida gravatar image

Furthermore to your answer, if you need to install a python package that goes with your myscript.py then you can also use ament to properly install it:

find_package(ament_cmake_python REQUIRED)
   ...
ament_python_install_package(my_package)

Where the my_package argument is a directory is alongside the CMakeLists.txt file with an __init__.py file in it.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2020-10-17 09:55:32 -0600

Seen: 1,174 times

Last updated: Feb 12 '22