Rosanswers logo


once a python package grows I would like to get files in module subfolders below the package. Also maybe other ressources as config or picture files would be good

How could I develop modules below the ros2 package make available to the ros2 package ?

To verify I have created that example package try_srv

where the test script combine_two_strings.py works fine

but the service combine_two_strings_server.py

failes with 'No module named combiner'

Thanks for any hint on that

Originally posted by vKuehn on ROS Answers with karma: 116 on 2019-03-29

Post score: 0

Original comments

Comment by gvdhoorn on 2019-03-29:
Please do not post screenshots of terminal text. It's all text, so just copy-paste it into your question.

As-is, your question now violates the Support Guidelines.

Comment by gvdhoorn on 2019-03-29:
Also please note: SUBPACKAGE in your screenshot is typically called module in Python. If you really meant "sub package", then nested packages are not supported.

Comment by vKuehn on 2019-03-31:
ok will remember the no screen shot policy next time. Is there a possibility to write my own modules ?

Comment by tfoote on 2019-03-31:
@vKuehn please edit your post so we can help you better. You can definitely write your own modules and embed them in the packages. It works like any other python package.

Comment by vKuehn on 2019-04-01:
@tfoote edited the post for clarification. I have also linked a very simple example to github where the failure can be reproduced / understood better. thanks for any review /hint


1 Answer 1


Rosanswers logo

A ROS package is defined as a directory with a package.xml file. Similar to how a CMake package (CMakeLists.txt) and Python package (setup.py) file is defined. Everything recursively under that directory is part of that package. As a consequence packages can't be nested.

Either you place multiple packages beside each other into sibling directories (see e.g. the ament_lint repository which contains numerous packages in sibling directories on the top level) or you keep adding content (like additional Python modules) to an existing package (see e.g. the launch package which contains many Python module below the launch subdirectory).

Originally posted by Dirk Thomas with karma: 16276 on 2019-04-01

This answer was ACCEPTED on the original site

Post score: 2

Original comments

Comment by tfoote on 2019-04-01:
Since you're nesting content inside the package everything needs to be caputured in your setup.py. I suspect that your different behavior is related to whether your PYTHON_PATH of your invocation and whether you're using the source space (ala the script) or the install space (ala the service) and if your setup.py is not installing all your resources then it could give you that error.

Comment by vKuehn on 2019-04-02:
thanks a lot to both of you guys ! Still not completetly sure why I saw that problem in a rospackage as I called the module as always (import from subfolders classes) Will look at the launch approach as it looks similiar

Comment by vKuehn on 2019-04-03:
made it work now so thanks again. For those interested the github in my question is now the working example


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.