Rosanswers logo

from the examples of ROS 2 I tried to copy the AddTwoInts Example to my own package. ros2 run try_srv add_two_ints_server generates an error when importing AddTwoInts

ModuleNotFoundError: No module named 'try_srv'

thought the reason is that the idl file is not generated (can't find them in install or build folder).

Changing from try_srv.srv import AddTwoInts back to from example_interfaces.srv import AddTwoInts works fine

this is the folder structure

image description

this is the package file

<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
  <description>migrated from examples</description>

  <license>Apache License 2.0</license>





is the folder and package.xml structure ok ?

if so what else could be the reason that the import fails ?

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

Post score: 2

Original comments

Comment by jayess on 2019-03-14:
Can you please update your question with a link to the tutorial that you're referring to?


1 Answer 1


Rosanswers logo

In ROS 2, message generation is done using the CMake macro rosidl_generate_interfaces, you can find an example of that macro invocation here.

As your package is a pure python package, it cannot invoke that CMake macro and generate the files.

Looking at your folder structure, the AddTwoInts_{Request,Reply}.msg files are not necessary. These will be generated automatically from your srv file.

In the package.xml: If your srv file depend on std_msgs, the std_msgs dependency needs to be listed as a build_depend as well as an exec_depend.

Finally, it is recommended to have the message definitions in a separate package and then import them from the packages that have the actual code and use them. If you want to use messages/services from the same package, you will need to specify it in your CMakeLists.txt by using the macro rosidl_target_interfaces, an example can be found here


Originally posted by marguedas with karma: 3606 on 2019-03-14

This answer was ACCEPTED on the original site

Post score: 2

Original comments

Comment by vKuehn on 2019-03-14:
thanks for the help will check it out

Comment by vKuehn on 2019-03-15:
now I was able to create a try_srv and a try_srv_msgs package which both work as expected. Thanks a lot


Your Answer

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