Exercise 3.3 ImportError: No module named my_custom_srv_msg_pkg.srv

I have been having a really tough time getting this exercise to work. I resorted to looking at the solutions and couldn’t find anything that would make a difference. I then directly copied the code from the solutions and re-made the catkin directory and I’m still unable to launch the package.

This is what I am getting so far:

Traceback (most recent call last):
File “/home/user/catkin_ws/src/my_custom_srv_msg_pkg/src/bb8_move_custom_service_server.py”, line 4, in
from my_custom_srv_msg_pkg.srv import MyCustomServiceMessage, MyCustomServiceMessageResponse
ImportError: No module named my_custom_srv_msg_pkg.srv
[service_move_bb8_in_circle_custom_server-1] process has died [pid 3557, exit code 1, cmd /home/user/catkin_ws/src/my_custom_srv_msg_pkg/src/bb8_move_custom_service_server.py __name:=service_move_bb8_in_circle_custom_server __log:=/home/user/.ros/log/ebef4f34-acc2-11e9-bcc3-0242ac120007/service_move_bb8_in_circle_custom_server-1.log].
log file: /home/user/.ros/log/ebef4f34-acc2-11e9-bcc3-0242ac120007/service_move_bb8_in_circle_custom_server-1*.log

Hi @pfautley,

Please look at the hints given in this post and let us know whether it solves your issue:

1 Like

Thank you for getting back to me @bayodesegun. Unfortunately, none of these troubleshooting steps have solved my problems so far. In my attempts to solve the problem I have had to directly copy the code from the examples and I’m still getting this issue, so the problem must stem from something else. Maybe an issue with the file names?



It’s usually one of the reasons stated in that post I shared. But it could also be a problem in the name of your message…are you trying to use a different name than the one defined.

It could also be a problem in the directory structure:

  • do you actually have a folder called srv in package my_custom_srv_msg_pkg?
  • is your service message properly defined in that folder?
  • in CMakeLists.txt, did you properly reference the service message as outlined in the note?

Please check all these again.

If you still can’t solve the error, you can send me a private message containing your package as a zip file. (You can download the package by right-clicking on the package folder name on the IDE and clicking “Download”). It might take some time before I’m able to review it.

I do think it’s probably a problem in the directory structure or the example code. I’d love to figure it out so I can learn more about custom services. Here are my answer to your proposed solutions:

  1. Yes, I have a folder called srv in the package my_custom_srv_msg_pkg. You can see my file structure here:


  1. My service message file is MyCustomServiceMessage.srv and contains exactly what was suggested in example 3.8
  2. I defined the service exactly as was detailed in example 3.8 (After trying to solve this on my own, I broke down and just copied the code exactly)

One thing that is confusing is that the example code has the line:

from my_custom_srv_msg_pkg.srv import MyCustomServiceMessage, MyCustomServiceMessageResponse

But the instructions detail that the package should be called my_custom_srv_msg_pkg and the actual file in the srv folder should be called MyCustomServiceMessage.srv Could this be the issue?


No, that’s fine. The problem here seems to be that your custom message was not properly built. I replied your pm, please check it and send me your package .zip file.

Hi @pfautley, I have checked your code and was able to run it without getting the error (PS: I only started the service, I didn’t test it).

How did I do it?

1. I compiled the package:

user:~/catkin_ws$ catkin_make --pkg my_custom_srv_msg_pkg

Please ensure that your package is located inside the top-level src folder: ~/catkin_ws/src:


2. I sourced the workspace:

user:~/catkin_ws$ source devel/setup.bash

3. I corrected a small error in the file bb8_move_custom_service_server.py


from my_custom_srv_msg_pkg import MyCustomServiceMessage, MyCustomServiceMessageResponse


from my_custom_srv_msg_pkg.srv import MyCustomServiceMessage, MyCustomServiceMessageResponse

Your need to import from [package].srv. Otherwise, you will get the error:

ImportError: cannot import name MyCustomServiceMessage

Can you try the same? In case that doesn’t work, try removing your build folder and build all packages again:

user:~/catkin_ws$ rm -rf build
user:~/catkin_ws$ catkin_make


Nothing worked until I removed the build packages and remade! Thank you for the help!


A post was split to a new topic: Problem creating a custom service message

Hello @pfautley,

I was getting the same import error. I did the following in order to solve the error.

  1. I added message_runtime in the
  CATKIN_DEPENDS rospy message_runtime
  1. Navigate to the catkin_ws directory and build the package using catkin_make <pkg_name>

  2. source the setup.bash using source devel/setup.bash file so that the new custom service will be included in the ROS environment.

Best of luck

1 Like

I had same issue until I made this " user:~/catkin_ws$ source devel/setup.bash"


Did you got the answer as I am having the same problem. I tried everything Still facing the same error

I am facing the same problem, can you please help me fix this I am attaching the error file for your reference. Hoe can I share zip file with you?

Hi, try removing your build/ and devel/ folders and sourcing your workspace again.

cd ~/catkin_ws
rm -rf build/ devel/
source devel/setup.bash

It’s not working bro

I’m looking at your screenshot and I don’t know why you’re saying you have the same error. This post is about Exercise 3.3 and it looks like you are in Unit 6. What exercise are you on?

Hellow everybody!

I’m trying to do the exercise 6.3 (I think the course was changed with more information) and I have the same problem. The strange thing is the custom message work before I create the new files at the working project! Also my_custom_msg… anda my_examples_pkg… Can anyone help me?

Hi, welcome to the community!

If you’ve tried deleting those folders and compiling again and it still doesn’t find your custom message package, then probably your best bet is to delete and create the package again