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

Import error: no module named Num.msg

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

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

Comments

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() a.data=[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

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

Question Tools

1 follower

Stats

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

Seen: 738 times

Last updated: Jan 08 '17