Ask Your Question

Import error: no module named Num.msg

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

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 -0500

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 -0500 )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 -0500 )edit

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

ahendrix gravatar image ahendrix  ( 2017-01-09 11:31:54 -0500 )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 -0500 )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 -0500 )edit

Thank you. Now it works.

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


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

Seen: 477 times

Last updated: Jan 08 '17