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

Install of the rospy/rosbag python libraries standalone not on Ubuntu

asked 2020-02-04 12:24:34 -0500

JohnH gravatar image

I want to be able to parse out bag files. I don't need to produce or change the bag files just read and parse them so I can use the data downstream in a couple of different systems/formats.

Using python is fine, and I am just trying to run this: import rosbag bag = rosbag.Bag('myfile.bag') for topic, msg, t in bag.read_messages(topics=['chatter', 'numbers']): print msg bag.close()

However, I can't seem to find a way to install the rosbag package.

I've tried variations of pip install rosbag.

From reading I see if I was on Ubuntu I should: sudo apt-get install python-rosbag

I don't have Ubuntu. Ideally I'd like to do this on CentOS and/or Mac OSX.

Of course, in testing on OSX, there's no apt-get and doesn't seem to be any homebrew equivalent...

Again I don't want to have to completely install ROS, just the python libs to parse the bag files.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2020-02-04 14:27:22 -0500

gvdhoorn gravatar image

updated 2020-02-04 15:04:42 -0500

Use the custom/experimental Pypi index from rospypi/simple:

virtualenv -p python3 venv
source ./venv/bin/activate
pip install --extra-index-url rospy rosbag

A couple of others packages might also come in handy, but that depends on what you want to do.

Also works with Python 2.

On Windows, Linux and most likely OSX as well (but I haven't tested it).

Related ROS Discourse post: Experimental Python package index for ROS.


Again I don't want to have to completely install ROS, just the python libs to parse the bag files.

seeing where you're registering from, you may be interested in this company which offers data analytics interopability tools for working with .bags (presentation at the ROS-I Conference 2019, and video recording).

I have no commercial interest here, just linking to a presentation I attended at the ROS-I Conf19 last year.

edit flag offensive delete link more


That worked. Thank you!

JohnH gravatar image JohnH  ( 2020-02-04 14:45:49 -0500 )edit

After doing this, I got the error Failed to load Python extension for LZ4 support. LZ4 compression will not be available

Kansai gravatar image Kansai  ( 2020-08-11 03:38:15 -0500 )edit

You'll want to discuss this with the maintainer of rospypi/simple.

gvdhoorn gravatar image gvdhoorn  ( 2020-08-11 07:36:11 -0500 )edit

I used the following to get rosbag working on macOS 10.15.7 Catalina with Python 3.8.5:

  1. brew install lz4
  2. brew install boost-python3
  3. pip install --extra-index-url rospy rosbag roslz4 cv-bridge
rajkundu gravatar image rajkundu  ( 2021-04-06 23:03:15 -0500 )edit

answered 2021-08-25 15:26:33 -0500

eRCaGuy gravatar image

updated 2021-08-25 15:27:01 -0500

According to this source:

This seems to work now to allow using import rosbag in your Python scripts:

# python2
pip install bagpy

# python3
pip3 install bagpy
edit flag offensive delete link more


Please note: bagpy is not an official package, but contributed by a community member.

That is of course +1 (without the community ROS would be dead), but as always, evaluate leaf packages like this properly to see whether they work for your use-case.

This seems to work now to allow using import rosbag in your Python scripts

yes, because under the hood it basically just installs rosbag.

gvdhoorn gravatar image gvdhoorn  ( 2021-08-26 01:50:21 -0500 )edit

Question Tools

1 follower


Asked: 2020-02-04 12:24:34 -0500

Seen: 16,936 times

Last updated: Aug 25 '21