ROS Services Quiz ModuleNotFoundError

My script bb8_move_custom_service_server.py is unable to import my custom message. The name of the package is services_quiz, I updated CMakeLists.txt and package.xml to the best of my ability, and I have run catkin_make and source devel/setup.bash. This is the error code:

File “/home/user/catkin_ws/src/services_quiz/src/bb8_move_custom_service_server.py”, line 4, in
from services_quiz.srv import BB8CustomServiceMessage, BB8CustomServiceMessageResponse
ModuleNotFoundError: No module named ‘services_quiz’

I can’t figure out how I can fix it and any help would be appreciated. Thank you

Hi Monica, welcome to the community!

Like you are stating, the problem comes because ROS is not finding your package services_quiz, so if you followed the instructions on how to create your custom message, then maybe removing your build/ and devel/ folders will help:

cd catkin_ws/
rm -rf build/ devel/
catkin_make
source devel/setup.bash
rospack profile

Hi that worked, thank you for your help!

I am now getting this error and am unsure of what it means:
File “/home/user/catkin_ws/src/services_quiz/src/bb8_move_custom_service_server.py”, line 5, in
from services_quiz.srv import BB8CustomServiceMessage, BB8CustomServiceMessageResponse
ImportError: cannot import name ‘BB8CustomServiceMessage’ from ‘services_quiz.srv’ (unknown location)
[bb8_move_custom_server-1] process has died [pid 2111, exit code 1, cmd /home/user/catkin_ws/src/services_quiz/src/bb8_move_custom_service_server.py __name:=bb8_move_custom_server __log:=/home/user/.ros/log/577c31ce-82e4-11eb-a9a3-0242ac1c0008/bb8_move_custom_server-1.log].
log file: /home/user/.ros/log/577c31ce-82e4-11eb-a9a3-0242ac1c0008/bb8_move_custom_server-1*.log

Hi Monica, I’m glad that worked. As for this error, the important part is this one:

ImportError: cannot import name ‘BB8CustomServiceMessage’ from ‘services_quiz.srv’ (unknown location)

It seems that your custom service message is not in the right location. Please make sure you follow the instructions on how to create it, paying special attention to the necessary additions to CMakeLists.txt and package.xml

Hi,

Thank you for your help!

This is what I have for CMakeLists.txt

This is what is have for package.xml

I copied the example given in the exercise so it’s likely I have it wrong for this application. I would really appreciate some assistance with fixing it!
Thank you

Hi Monica,

In your CMakeLists.txt, I see that in functions add_service_files() and generate_messages(), some extra letters seem to have been copied there. You should remove “&nbsp” from these 4 lines:

image

Sorry that seemed to be generated when I copied and pasted. My actual does not contain those extra letters yet it does not work

I had the same problem and I could solve it compiling only the package which I am working with:

catkin_make --only-pkg-with-deps <package_name>

1 Like

I tried this and getting an error message please guide me through this

Hi,

I’m gonna need more info than that. Are you trying to compile the workspace while doing the services quiz? The error from the OP shows that her service wasn’t being generated correctly, while yours shows the failure to find iri_wam_reproduce_trajectory package. This is a package that comes preinstalled, so the problem is usually that the sourcing is not correct. If this is the case, you can remove your build/ and devel/ folders and try compiling and sourcing again.

I also went into your account and noticed an error: in your catkin_ws, you have an extra package next to the build, devel, and src/ folders. You should never have packages in there along those three. You have to move it under your src/ folder.