ERROR: Cannot load message class for [package/Message]. Are your messages built?

This error usually happens when you create a custom ROS message.

SOLUTION:

Please check the following in order. Painfully :slight_smile:, #3 is a common and repeated cause, and it tends to happen even if you already know about it!

  1. Have you made the necessary and correct modifications to your CMakeLists.txt (and, where required, package.xml) file after creating the message file? You can find instructions on how to do this in the relevant section of the notebook describing how to create custom messages for ROS topics or actions,in the ROS Basics In 5 Days course.
  2. Have you run catkin_make?
  3. Have you run source devel/setup.bash on EVERY shell where you are using the custom message? If you’re working on a local PC, you can put this command in your ~/.bashrc file so that it runs for every new shell, but for shells that are already open you still need to run this command or source ~/.bashrc.

PS: You must run catkin_make from the catkin_ws directory. Also, the command given in #3 assumes that you will run it from catkin_ws.

user:~/catkin_ws$ catkin_make                    # run on only one of the shells
user:~/catkin_ws$ source devel/setup.bash        # run on EVERY shell

If you have done all this and the problem is still there, try removing the build folder and then rebuilding and sourcing again:

user:~/catkin_ws$ rm -rf build
user:~/catkin_ws$ catkin_make                    # run on only one of the shells
user:~/catkin_ws$ source devel/setup.bash        # run on EVERY shell
3 Likes

Hello, I did all (incl. PS) advices and the error turned from:
“ImportError: No module named my_custom_srv_msg_pkg.srv”
to error:
“ImportError: No module named srv”

Could you please help me?

Thank you very much.

Hello, I solved it. I had an error in CMakeLists.txt of different package, so the compilation was not finalized correctly and was finished with error. Thank you.

1 Like