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

"No module named rosbag" error

asked 2011-12-11 14:36:13 -0600

suzuki tarou gravatar image

updated 2014-01-28 17:10:59 -0600

ngrennan gravatar image

I followed guide at http://www.ros.org/doc/api/rosbag/html/c++/ I runned the example usage read bag file by Python,

import rosbag
bag = rosbag.Bag('test.bag')
for topic, msg, t in bag.read_messages('numbers'):
   print msg.data
bag.close();

when i run the code it tells me "ImportError: No module named rosbag"

Traceback (most recent call last): File "/home/user/ros_workspace/beginner_tutorials/nodes/read_bag.py", line 4, in <module> import rosbag ImportError: No module named rosbag

please tell me how to fix this!

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
3

answered 2011-12-11 16:41:28 -0600

fergs gravatar image

Have you added a dependency on the 'rosbag' package in your package manifest.xml?

edit flag offensive delete link more

Comments

Also you will need to use roslib.load_manifest to get the module onto your PYTHONPATH There are tutorials on using python in ROS at http://www.ros.org/wiki/rospy_tutorials/Tutorials
tfoote gravatar image tfoote  ( 2012-01-02 06:37:36 -0600 )edit
0

answered 2021-09-28 16:56:57 -0600

eRCaGuy gravatar image

updated 2021-09-29 12:30:30 -0600

I'm having this problem come up a lot for people using my ros_readbagfile program, while following my ROS tutorial here: Reading messages from a bag file.

I've documented the solution here: https://stackoverflow.com/questions/5...

See the link above for full details, but the gist of it is this:

TLDR;

Run this:

pip3 install bagpy
# OR, if that ends up failing in the end due to a "Permission denied" error, 
# do this:
sudo pip3 install bagpy

Now this will work in your Python 3 script:

import rosbag

...so long as you have the correct hash-bang at the top of your Python 3 file, such as this one:

#!/usr/bin/env python3

Again, see the Stack Overflow link above for additional details.

edit flag offensive delete link more

Comments

Please do not post link-only answers.

We have a similar policy regarding such answers as Stack Overflow: answers should be written such that they are stand-alone.

Quote the relevant parts of your SO post here in your answer.

gvdhoorn gravatar image gvdhoorn  ( 2021-09-29 01:54:51 -0600 )edit

@gvdhoorn, done. I added the fundamental parts of the answer.

eRCaGuy gravatar image eRCaGuy  ( 2021-09-29 12:34:40 -0600 )edit

Thanks.

It's shebang btw, not hash-bang (edit: apparently both are ok).

gvdhoorn gravatar image gvdhoorn  ( 2021-09-29 13:48:49 -0600 )edit

@gvdhoorn, yeah: shebang = sha-bang = hashbang = pound-bang = hash-pling, as you found out in the wikipedia article: https://en.wikipedia.org/wiki/Shebang....

eRCaGuy gravatar image eRCaGuy  ( 2021-09-29 14:31:43 -0600 )edit

You learn something new everyday :)

osilva gravatar image osilva  ( 2021-09-29 18:25:40 -0600 )edit

Question Tools

Stats

Asked: 2011-12-11 14:36:13 -0600

Seen: 14,339 times

Last updated: Sep 29 '21