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

ImportError: No module named launch

asked 2021-10-20 05:07:56 -0500

jjb1220 gravatar image

updated 2021-10-26 08:49:32 -0500

lucasw gravatar image

Hello, I ran ./ to run a python file on ros2 supported open source . But I am getting the following error: I followed the installation instructions in the Ros2 basic documentation and just run the file.

I'm running on Ubuntu 18.04 eloquent-devel and I added #!/usr/bin/env python to the first line of python.
Traceback (most recent call last):
  File "./", line 3, in <module>
    from launch import LaunchDescription
ImportError: No module named launch

The code below is the python code I want to run.


from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node

def generate_launch_description():
    return LaunchDescription([
            name='scanner', default_value='scanner',
            description='Namespace for sample topics'
            package='pointcloud_to_laserscan', executable='dummy_pointcloud_publisher',
            remappings=[('cloud', [LaunchConfiguration(variable_name='scanner'), '/cloud'])],
            parameters=[{'cloud_frame_id': 'cloud', 'cloud_extent': 2.0, 'cloud_size': 500}],
            arguments=['0', '0', '0', '0', '0', '0', '1', 'map', 'cloud']
            package='pointcloud_to_laserscan', executable='pointcloud_to_laserscan_node',
            remappings=[('cloud_in', [LaunchConfiguration(variable_name='scanner'), '/cloud']),
                        ('scan', [LaunchConfiguration(variable_name='scanner'), '/scan'])],
                'target_frame': 'cloud',
                'transform_tolerance': 0.01,
                'min_height': 0.0,
                'max_height': 1.0,
                'angle_min': -1.5708,  # -M_PI/2
                'angle_max': 1.5708,  # M_PI/2
                'angle_increment': 0.0087,  # M_PI/360.0
                'scan_time': 0.3333,
                'range_min': 0.45,
                'range_max': 4.0,
                'use_inf': True,
                'inf_epsilon': 1.0
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-10-21 18:29:37 -0500

miura gravatar image

I think /usr/bin/python is python2. ROS2 works with python3, and it is expected that launch cannot be found because of python2. Replace /usr/bin/python with python3 (/usr/bin/python3?) and it should work.

edit flag offensive delete link more


Thanks for the reply. As per your advice, I put python instead of python and tried to run it again, but the same error is output. I put both python2 and python and tried to run it.

jjb1220 gravatar image jjb1220  ( 2021-10-22 23:48:28 -0500 )edit

If changing to python3 didn't help, then you probably don't have launch installed. Have you tried running a ROS2 python script that doesn't use a different launch? Does it work?

miura gravatar image miura  ( 2021-10-23 17:52:54 -0500 )edit

Question Tools


Asked: 2021-10-20 05:07:56 -0500

Seen: 3,129 times

Last updated: Oct 23 '21