ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Import error: no module named Num.msg

asked 2017-01-08 11:58:58 -0600

hvn gravatar image


I want to use my own msg, and try this:

from Num.msg import *

and get the import error. Num.msg is in <package>/msg/ and is found by "rosmsg show". When I don't import, codeline "a = Num()" gets error "Global name 'Num' is not defined". What do I miss?



edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-01-08 13:47:03 -0600

ahendrix gravatar image

The python package for messages is named after the ROS package name, not the message name.

This means that the import syntax for a single message is:

from my_package.msg import MyMessage

Or for all messages in a package:

from my_package.msg import *

It looks like you should change Num to your package name. (note that package and message names are case-sensitive)

edit flag offensive delete link more


Based on your other question ; the import should be from robot_pi.msg import Num or from robot_pi.msg import *

ahendrix gravatar image ahendrix  ( 2017-01-08 13:48:05 -0600 )edit

Ok, I've changed its name to robot_pi.msg, leaving its content intact: [code]int32[] data[/code] Now I want to this for publishing: pub=rospy.Publisher('speaker', int32, queue_size=10) a=robot_pi()[1,2,3] and still get the errors. Where do I go wrong?

hvn gravatar image hvn  ( 2017-01-09 03:42:10 -0600 )edit

The message name is Num, so use that when you create the publisher.

ahendrix gravatar image ahendrix  ( 2017-01-09 11:31:54 -0600 )edit

I changed Num.msg into robot_pi.msg and changed CMakelists.txt accordingly. New robot_pi.msg doesn't contain Num but "int32[] data". So how is the message name Num? I assume create the publisher is pub = rospy... so int32 should be replaced by the message name?

hvn gravatar image hvn  ( 2017-01-09 11:47:59 -0600 )edit

Ok, if you're renamed your message file (that wasn't clear from your previous post), then the message name is now robot_pi.

ahendrix gravatar image ahendrix  ( 2017-01-09 13:11:22 -0600 )edit

Thank you. Now it works.

hvn gravatar image hvn  ( 2017-01-09 13:37:31 -0600 )edit

Hii, in my case it gives error that my_package.msg not found

my scripts folder is in the my_package folder

Rutvik gravatar image Rutvik  ( 2023-06-11 11:58:41 -0600 )edit

Question Tools

1 follower


Asked: 2017-01-08 11:58:58 -0600

Seen: 725 times

Last updated: Jan 08 '17