ModuleNotFoundError. Exercise 4.3 of ROS Basics in 5 Days

I’ve created my own message to show the age of the robot, but I keep getting this error. I believe I have correctly made the changes in CMakeList and Package.xml files. The msg shows up in rosmsg show, but gives error in python script. I have made sure to catkin_make and source devel/setup.bash too. Help!

Hi @Yogesh_G ,

  1. Could you post the contents of your message?
  2. If you have used your custom message in a program code, could you also post that program code here?

Please use the Preformatted Text </> in your reply to encapsulate your code.

Sure, here are the contents: -

age.msg file: -
path - ~/catkin_ws/src/read_odom_pkg/msg

float32 years
float32 months
float32 days

The program code, -

#! /usr/bin/env python

import rospy
from read_odom_pkg.msg import age

rospy.init_node('age_publisher_node')  # Initiating node.
# Defining publisher.
pub = rospy.Publisher('/age_pub_topic', age, queue_size=1)

rate = rospy.Rate(2)  # 2Hz publish rate.

a = age()

a.years = 22  # Defining the msg
a.months = 8
a.days = 15

while not rospy.is_shutdown():  # Loop till force shutdown
    pub.publish(a)  # Publish.
    rate.sleep()  # sleep to match publish rate.

@Yogesh_G ,

Your age.msg and your looks fine. Only difference is that you are using float instead of int for age variables.

Could you post your error traceback as a screenshot ?

Also, did you add std_msgs as a dependency to CMakeLists.txt and package.xml?

Yes, I have added std_msgs as a dependency to CMakeList.txt and package.xml.
This is the error’s screenshot: -

@Yogesh_G ,

That is weird. Are you sure you created read_odom_pkg using catkin_create_pkg and not using mkdir?

Did you do catkin_make after you created the custom message?

Did you try rosrun read_odom_pkg ?

Yes I did! I used

and did
as well as source the
file too. Hence I’m confused what’s going wrong.

Just tried rosrun,

Same error.

@Yogesh_G ,

I am actually out of ideas. All your steps seem to be correct.
Unless using float instead of int is a problem, which I think will not be, you should not get this error.

As a last resort, I would tell you to re-create the package from scratch.


Hey @girishkumar.kannan , I made the complete package again. tried different names and used int32 instead of float32, but the error still persists. I get the same traceback error.

Thankyou for your time and help!

Hi @Yogesh_G
I was facing the same issue till yesterday. i cleaned my workspace and then it worked. Your codes are alright try cleaning your workspace once. I suppose when you are using catkin_make the packages are not updating. Thus if you clean and reset your workspace everything should work fine.
For the process of resetting kindly follow the following link

hope it helps.
Cheers Mate


Hey @ra130 , I used your suggestion and it helped me. Thanks a lot for the help.

1 Like

This topic was automatically closed after 17 hours. New replies are no longer allowed.