Ask Your Question
1

Import error: no module named Num.msg

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

hvn gravatar image

Hi,

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?

Thanks,

hvn

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

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

Comments

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

ahendrix gravatar imageahendrix ( 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() a.data=[1,2,3] and still get the errors. Where do I go wrong?

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

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

ahendrix gravatar imageahendrix ( 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 imagehvn ( 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 imageahendrix ( 2017-01-09 13:11:22 -0600 )edit

Thank you. Now it works.

hvn gravatar imagehvn ( 2017-01-09 13:37:31 -0600 )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

Stats

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

Seen: 381 times

Last updated: Jan 08 '17