ROS2 Python package only recognized with `colcon build --symlink-install`

asked 2022-08-10 04:57:18 -0600

Peter1 gravatar image

I have a ros2 work space with two python packages. Package2 imports package1 with

from package1.helpers import Helper

I set up the setup.cfg and according to the basic ros2 tutorial. I add an <exec_depend>package1</exec_depend> to the package.xml of package2.

When I build the packages with the colcon build --symlink-install, source install/setup.bash, I can run package2 and everything works fine.

When I do colcon build, source install/setup.bash without using symbolic links, and run package 2, I get the error message: ModuleNotFoundError: No module named 'package1.helpers'

I even tried installing package1 manually with pip, but it is not recognized. I see that my python package1 is copied into the ros workspace's build directory, so I would assume, it is there to be recognized. The ros2 documentation, does not add any insights.

Which step am I missing? I want to be able to load my ros2 python nodes without using the sym-links

edit retag flag offensive close merge delete


You can check your code with these steps, I found it really useful. Maybe it is a missing dependency ament_python/rclpy in package1 or package2?

ljaniec gravatar image ljaniec  ( 2022-08-10 07:28:46 -0600 )edit

the dependencies are correclty set, I tried again with changing from a based package to a cmake package. with this it works, so I assume it is a problem with the python ros2 configuration

Peter1 gravatar image Peter1  ( 2022-08-11 05:29:38 -0600 )edit

Did you create your package using catkin_create_pkg or by manually creating the files? In package1, did you export in the file?

achille gravatar image achille  ( 2023-01-24 15:21:20 -0600 )edit