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

Revision history [back]

As @Joe28965 has already mentioned, you need to install other files in a ROS2 Python package (e.g. laucnh files etc.).

You can use this step by step tutorial for it:

https://roboticsbackend.com/create-a-ros2-python-package/#Explanation_of_files_inside_a_ROS2_Python_package

Especially part with:

Launch files

Create a launch/ folder at the root of your package. You’ll put all your launch files inside this folder.

cd ~/ros2_ws/src/my_python_pkg/
mkdir launch

Now, to install those launch files, you need to modify setup.py.

import os
from glob import glob
from setuptools import setup
...
data_files=[
    ('share/ament_index/resource_index/packages',
        ['resource/' + package_name]),
    ('share/' + package_name, ['package.xml']),
    (os.path.join('share', package_name, 'launch'),

glob('launch/*.launch.py')), ], ...

For our example, with package name my_python_pkg, this will install all launch files from the launch/ folder, into ~/ros2_ws/install/my_python_pkg/share/my_python_pkg/launch/.

Note: you only need to modify setup.py once. After that, every time you add a launch file you’ll just need to compile your package so that the file is installed, that’s it.

As @Joe28965 has already mentioned, you need to install other files in a ROS2 Python package (e.g. laucnh launch files etc.).

You can use this step by step step-by-step tutorial for it:

https://roboticsbackend.com/create-a-ros2-python-package/#Explanation_of_files_inside_a_ROS2_Python_package

Especially part with:

Launch files

Create a launch/ folder at the root of your package. You’ll put all your launch files inside this folder.

cd ~/ros2_ws/src/my_python_pkg/
mkdir launch

Now, to install those launch files, you need to modify setup.py.

import os
from glob import glob
from setuptools import setup
...
data_files=[
    ('share/ament_index/resource_index/packages',
        ['resource/' + package_name]),
    ('share/' + package_name, ['package.xml']),
    (os.path.join('share', package_name, 'launch'),

glob('launch/*.launch.py')), ], ...

For our example, with package name my_python_pkg, this will install all launch files from the launch/ folder, into ~/ros2_ws/install/my_python_pkg/share/my_python_pkg/launch/.

Note: you only need to modify setup.py once. After that, every time you add a launch file you’ll just need to compile your package so that the file is installed, that’s it.

As @Joe28965 mentioned, you need to install other files in a ROS2 Python package (e.g. launch files etc.).

You can use this step-by-step tutorial for it:

https://roboticsbackend.com/create-a-ros2-python-package/#Explanation_of_files_inside_a_ROS2_Python_package

Especially part with:

Launch files

Create a launch/ folder at the root of your package. You’ll put all your launch files inside this folder.

cd ~/ros2_ws/src/my_python_pkg/
mkdir launch

Now, to install those launch files, you need to modify setup.py.

import os
from glob import glob
from setuptools import setup
...
data_files=[
    ('share/ament_index/resource_index/packages',
        ['resource/' + package_name]),
    ('share/' + package_name, ['package.xml']),
    (os.path.join('share', package_name, 'launch'),
    glob('launch/*.launch.py')),
 ],
...

glob('launch/*.launch.py')), ], ...

For our example, with package name my_python_pkg, this will install all launch files from the launch/ folder, into ~/ros2_ws/install/my_python_pkg/share/my_python_pkg/launch/.

Note: you only need to modify setup.py once. After that, every time you add a launch file you’ll just need to compile your package so that the file is installed, that’s it.