Ask Your Question
1

can't install rosbag package

asked 2018-03-03 04:51:42 -0500

anonymous user

Anonymous

updated 2018-03-04 08:04:44 -0500

Ubuntu 16.04 LTS Xenial ROS Kinetic

Linux novice, ROS novice.

Have a catkin workspace with some packages in it (robot_localization etc).

import rosbag

gives error

import error: no module named rosbag

so tried installing:

sudo apt-get update
sudo apt-get install python-rosbag

get error:

p@t:~$ sudo apt-get install python-rosbag
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 python-rosbag : Depends: python-roslib but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

What should I do? How do i fix the import error?

Edit I'm sorry. I've been at this for months now. I didn't study for this. Frustration is making me go crazy.

$ which python returns "/usr/bin/python" now. I assume this is what it's supposed to be? $ grep -i anaconda /home/pieter/.bashrc returns "grep: /home/pieter.bashrc: No such file or directory" if that's still relevant

$ ~/folderimworkingin python file.py now returns with error ending in

File "/opt/ros/kinetic/lib/python2.7/dist-packages/genmsg/msg_loader.py", line 83, in get_msg_file
    % (base_type, package, search_path), base_type, package, search_path)
genmsg.msg_loader.MsgNotFound: Cannot locate message [Header]: unknown package [std_msgs] on search path [{}]

So am I missing a message package now or?

Edit

pieter@turing:~/benchmarking$ rospack find std_msgs
/opt/ros/kinetic/share/std_msgs

Seems reasonable.

>>> import std_msgs
>>>

does not complain.

Python --version

returns 2.7.12 now (instead of 2.7.14).

File.py:

#import numpy as np
#import scipy.io
from bag import get_topic_data
testfile = "/home/pieter/benchmarking/bagfiles/2018-03-03-11-13-48.bag"
testdata = get_topic_data(testfile,"/android/imu")
#size = len(testdata)
#print(size)

with bag.py:

import rosbag
def get_topic_data(bagFile, topic):
    all_msg = []        
    # Initialize rosbag object
    bag = rosbag.Bag(bagFile)        
    for topic, msg, t in bag.read_messages(topics=[topic]):            
        all_msg = np.append(all_msg, msg)    
    return all_msg

bag file I think is accessible?:

https://github.com/PieterVanB/bagfile
edit retag flag offensive close merge delete

Comments

This is all greek to me.

I sympathise with you, but please refrain from making these types of comments.

gvdhoorn gravatar image gvdhoorn  ( 2018-03-04 07:37:51 -0500 )edit

@OperationCrossbow: did fixing the bag fix the issues you were having with your script?

gvdhoorn gravatar image gvdhoorn  ( 2018-03-05 08:52:59 -0500 )edit

@gvdhoorn installed the bagfixer, did catkin_make. source bashed, new terminal. says can't find "fix_bag_msg_def.py" even though it's executable and in the same folder as the input bag. But i'm googlin'.

anonymous userAnonymous ( 2018-03-05 12:07:51 -0500 )edit

It's not a catkin package, so catkin_make is not needed.

You only need to clone the repository, go to the directory where your bag is and then do something like:

$ /path/to/where/bag_fixer/is/fix_bag_msg_def.py [...] out.bag
$ rosbag reindex out.bag

That's it.

[...] is the other args.

gvdhoorn gravatar image gvdhoorn  ( 2018-03-05 13:29:49 -0500 )edit

Btw: to run programs/scripts in the current directory, always prefix the name of the script or program with ./. Otherwise bash will not be able to find the program (unless it's on the path).

gvdhoorn gravatar image gvdhoorn  ( 2018-03-06 02:09:16 -0500 )edit
gvdhoorn gravatar image gvdhoorn  ( 2018-03-08 05:37:24 -0500 )edit

@gvdhoorn pieter@turing:~/benchmarking/bagfiles$ /catkin_ws/src/rosbag_fixer/fix_bag_msg_def.py --use-local-defs 2018-03-03-11-13-48.bag out.bag

returns: bash: /catkin_ws/src/rosbag_fixer/fix_bag_msg_def.py: No such file or directory

What am I missing?

anonymous userAnonymous ( 2018-03-09 13:16:10 -0500 )edit

You're specifying an absolute path. That starts at the root of your file system and looks for a directory catkin_ws in the root, instead of in your home directory. That won't work.

You can either prefix with the path to ..

gvdhoorn gravatar image gvdhoorn  ( 2018-03-09 13:29:54 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-03-03 05:05:48 -0500

gvdhoorn gravatar image

updated 2018-03-04 09:13:49 -0500

Edit 9:

I've updated the tool and ran your bag through it as follows:

$ fix_bag_msg_def.py --use-local-defs 2018-03-03-11-13-48.bag out.bag
$ rosbag reindex out.bag

This replaced 6 message definitions for me. Afterwards the bag was usable. I have tested your script and I now get errors about np not being defined (which is not imported, so that error makes sense).

See the readme of gavanderhoorn/rosbag_fixer for some more information on how to use it.


Edit 8: ok. I believe I know what is going on.

Overview of your situation:

  1. your initial problem ("cannot install rosbag") was solved/a non-problem: it was already installed, and python-rosbag is not actually the pkg you want to install on Ubuntu if you already have ros-kinetic-rosbag.
  2. the "cannot import rosbag" problem was also solved/worked-around: you were using Anaconda, and the binary packages distributed via the official OSRF package repositories do not support that (the modules are installed in the 'regular' location, and Anaconda doesn't pick those up). You can later try and get Anaconda to work again.

Now as to your latest edit: you didn't mention it (I didn't ask, and I should've), but you're trying to load a bag with messages published by rosjava (ROS Java is used by ROS Android under the hood). There is a known issue with rosjava that prevents this from working.

For some references, see ros/common_msgs#20 and rosjava/rosjava_bootstrap#16 (and #q108956, a related question). Note the error message included in the comments on the first issue, it's virtually identical to yours. The problem is described in rosjava/rosjava_bootstrap#16:

It appears that published messages are missing the message definition for the child types which is used for message introspection

In a nutshell this means that rosbag has no way of figuring out what the format of the data is you're trying to load from your bag, and thus cannot continue processing it. Hence the exception. Looking at your script however it appears to be ok, and should work with just about any bag file that doesn't contain messages published by rosjava.

So to summarise: everything is ok now, it's just that you've run into an issue with rosjava that prevents your script from working (note: this is different from the script being syntactically ok and the runtime environment being able to load all required libraries, as was the problem before).

I've ran into this issue myself, and wrote a simple tool to try and fix bags that contain messages published by rosjava: gavanderhoorn/rosbag_fixer. I can't guarantee it will work and it's rather underdocumented (I only needed it once). If you can provide your bag I'm willing to try and fix it for you. Afterwards I'll update my answer with the steps needed to fix arbitrary bags so you can do it yourself if you need to -- I can't remember them now.

(note: I placed my ... (more)

edit flag offensive delete link more

Comments

How I installed ROS and the current packages I own is in 4 hours time with several USB-stick reboots and complete wipes of my computer, with a doctorate student sitting next to me telling me what to do. Idk what upstreamed packages are.

Also: "ros-kinetic-rosbag is already the newest version".

anonymous userAnonymous ( 2018-03-03 05:49:14 -0500 )edit

How I installed ROS and the current packages I own is in 4 hours time with several USB-stick reboots and complete wipes of my computer, with a doctorate student sitting next to me telling me what to do

A link to a tutorial would have sufficed.

And Linux != ROS.

gvdhoorn gravatar image gvdhoorn  ( 2018-03-03 05:54:11 -0500 )edit

Also: "ros-kinetic-rosbag is already the newest version".

That is ok. It means you already have that package, which is expected.

What is the output of python --version?

gvdhoorn gravatar image gvdhoorn  ( 2018-03-03 05:54:25 -0500 )edit

Idk what upstreamed packages are.

that is why I linked you to the article on the wiki that explains it.

gvdhoorn gravatar image gvdhoorn  ( 2018-03-03 05:54:50 -0500 )edit

@gvdhoorn Ah, sorry. My frustration is getting the better of me. Python is 2.7.14. The doctorate student (my thesis copromotor) told me this is probably the best to use (like Anaconda 2) because it's more stable, works better with ROS, etc, etc.

anonymous userAnonymous ( 2018-03-03 06:13:40 -0500 )edit

So is this Anaconda? What is the output of which python? If you already have ros-kinetic-rosbag, there should be files under /opt/ros/kinetic/lib/python2.7/dist-packages/rosbag. You did source /opt/ros/kinetic/setup.bash?

gvdhoorn gravatar image gvdhoorn  ( 2018-03-03 06:34:17 -0500 )edit

(1) returns: "home/username/anaconda2/bin/python." (2) yes, rosbag is there (3) Yes; there is source /opt/~~/setup.bash is in my bashrc file, so everytime I open a new terminal it should source this.

anonymous userAnonymous ( 2018-03-03 06:48:30 -0500 )edit

@gvdhoorn still feel like helping me?

anonymous userAnonymous ( 2018-03-03 08:19:34 -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

Stats

Asked: 2018-03-03 04:51:42 -0500

Seen: 9,117 times

Last updated: Mar 04 '18