ModuleNotFoundError in quiz of unit 6

I have a problem with the quiz for unit 6. The package contains all launch files, python scripts, and a message file. The catkin_ws folder has been rebuilt with catkin_make. The CMakeLists.txt and package.xml have also been updated and names have been double-checked. However, I keep getting the following error when I try to launch the server:

Traceback (most recent call last):
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’

The error occurs in the python code. I have already tried to take over the complete package from someone else, where everything worked as expected, but I still get the same error. So I am wondering if I might be doing something wrong in creating the package. I use the following commands:

cd ~/catkin_ws/src/
catkin_create_pkg services_quiz rospy
roscd services_quiz
mkdir srv
mkdir launch
touch srv/BB8CustomServiceMessage.srv
touch launch/start_bb8_move_custom_service_server.launch
touch launch/call_bb8_move_in_square_custom_service_server.launch
touch src/bb8_move_custom_service_client.py
touch src/bb8_move_custom_service_server.py
touch src/move_bb8.py
cd src
chmod +x bb8_move_custom_service_client.py
chmod +x bb8_move_custom_service_server.py
chmod +x move_bb8.py

roscd;cd …
catkin_make clean
catkin_make
source devel/setup.bash

rossrv list | grep BB8CustomServiceMessage
Output:
services_quiz/BB8CustomServiceMessage

roslaunch services_quiz start_bb8_move_custom_service_server.launch
Output:
The error message as shown above.

Quick tip: ensure you run source ~/catkin_ws/devel/setup.bash in every shell where you want to use the message.

The error suggests that your message was not built or sourced. If indeed you have sourced all shells, please let’s see the structure of your package in a screenshot.

Thanks for the quick tip, but the first tip did not solve the problem.

This is the structure of my package.

Me sucede lo mismo que a vos y no lo puedo resolver

Looks okay.

Something is not right, if things are this way. For example, I wonder why we could have

rossrv list | grep BB8CustomServiceMessage
Output:
services_quiz/BB8CustomServiceMessage

and yet have that error. Is there misspelling or conflicts somewhere?

Try:

cd ~/catkin_ws
rm -rf build/ devel/
catkin_make
source devel/setup.bash  # run this on every shell

and try again.

If the problem persists, please send us a full-screen screenshot of the Desktop page showing the error.

Thanks for thinking along. When I run the command rossrv list I get the desired result as shown above. Here is a full screenshot of the error I am getting. As a test, I also tried the code of a fellow student on my laptop. The code worked perfectly for my fellow student, but I keep getting the same error for me. Could it be something to do with the PC? Are some files created locally where something can go wrong? Thanks again for thinking along.

@ArjanvdE , no this couldn’t be a problem with the PC as everything runs in the cloud.

I assume you have made the modifications in your package.xml and CMakelists.txt in order to generate the message you want to import, but just check them again just in case.

Does the service message appear with rossrv show? You can also try doing from services_quiz.srv import *, although I don’t think it will work if what you are trying is also not working.

The last thing I can think about is just creating the package again, something might be wrong with the internal build of the package, because I can’t spot an error in your screenshots.

@roalgoal , thanks for the suggestions. The command rossrv show does not show anything, but I do not know if that is because no service is running yet, since launching the server already causes the error in the python file. I already tried to recreate the package once, but without success. Could it be an error somewhere in the workspace, catkin_ws?

I managed to figure out what the problem was. Just creating a new package was not enough. I have created a new workspace (catkin2_ws) containing a new package. I have created all the folders and files in it. I copied the content of the code from the old workspace. After building and sourcing the new workspace, everything worked as it should. Probably something went wrong somewhere in the old workspace, but I cannot figure it out.

@bayodesegun and @roalgoal, thanks for thinking along!

1 Like