The core reason behind No module named 'roslaunch'

Problem

You’re running or launching some ROS package, but you see an error message such as

the-core-reason-behind-no-module-named-roslaunch_block1.txt
No module named 'roslaunch'
```plaintext {filename="the-core-reason-behind-no-module-named-roslaunch_block2.txt"}

## Reason

The core reason for this is **that `roslaunch` is from ROS 1, whereas you're using ROS 2**.

Therefore, you must be mixing ROS 1 and ROS 2 packages in some way.

The next step for you would be to find out which package uses `roslaunch` and then find a ROS 2 equivalent for that package.
/home/uli/.local/lib/python3.12/site-packages/xacro/__init__.py
```sh {filename="search_roslaunch.sh"}
ag -i roslaunch
```plaintext {filename="__init__.py"}

Sometimes this happens because you've installed Python packages somewhere (outside the main ROS2 
directory, for example using `pip`) and these ROS1 packages are still in your `PYTHONPATH`.

In case you are using `ros2 launch`, see our post [ROS2 hack to enable DEBUG logging during 'ros2 launch'](/2025/01/24/ros2-hack-to-enable-debug-logging-during-ros2-launch/) for an easy hack to see the stacktrace where `roslaunch` is being imported from.

In my case, I installed a copy of `xacro` to `~/.local/lib/python3.12/site-packages/xacro/__init__.py`.

Therefore, I needed to uninstall `xacro` using

```sh {filename="pip_uninstall_xacro.sh"}
pip uninstall xacro
```plaintext {filename="__init__.py"}

and then install the ROS2 version of `xacro` using

```sh {filename="install_ros_xacro.sh"}
sudo apt -y install ros-jazzy-xacro
```plaintext {filename="install_ros_xacro.sh"}

Check out similar posts by category: ROS