0
$\begingroup$

Rosanswers logo

I apologize if this is a seemingly very simple question, but I am stumped. I am trying to do the tutorials for rosbag: http://wiki.ros.org/rosbag/Code%20API using the Python example for read, and I get the following error:

Traceback (most recent call last):
  File "rosbag.py", line 1, in <module>
    import rosbag
  File "/home/jason/Documents/Testing_rospy/rosbag.py", line 3, in <module>
    bag = rosbag.Bag('test.bag')
AttributeError: module 'rosbag' has no attribute 'Bag'

I am using a VM with Ubuntu 16.04 32-bit running ROS kinetic. I assume there's a dependency I'm missing for using rosbag with python (3.6.1, editing with Sublime Text). I am able to run the yaml import from 1.3 here: http://wiki.ros.org/rosbag/Cookbook and I can get the info from the terminal and view the bag msgs in rqt. My python IDE works fine since I can create .py files and run them from the terminal with expected behavior.

I tried to look through as many files as I could and I've seen things on configuring the PYTHONPATH correctly, but nothing specific to rosbag. I would greatly appreciate it if someone could point me in the right direction.

Thanks!


Originally posted by jmm2270 on ROS Answers with karma: 3 on 2018-05-10

Post score: 0


Original comments

Comment by gvdhoorn on 2018-05-10:
If you installed ROS using apt (or apt-get) then there is no Python 3 support. But I would have expected the import to already fail.

If you installed things in a different way, then please tell us how, as that is going to be important.

Comment by jmm2270 on 2018-05-10:
Thanks for the quick response. I installed python using apt-get. Is there a tutorial I can reference to do things the correct way? For example, am I supposed to execute my python code using "python file.py" or some other way with ros? Again, sorry for the how basic this question is.

Comment by gvdhoorn on 2018-05-10:
My comment was not about how you installed Python, but ROS. The default ROS pkgs don't support Python 3. You're using 3.6.1 according to your description. The ROS pkgs you install using apt-get don't support Python 3.

Comment by gvdhoorn on 2018-05-10:
In addition: you have named your own script rosbag.py. That is not a good idea, as it will shadow (ie: hide) the rosbag that you're trying to use.

Comment by jmm2270 on 2018-05-11:
Thanks for the tips. Here's what I did today: set up a new environment with python 2.7.15 and reinstalled all dependencies (I think), then renamed my python script. I tried just simply to "import rosbag" and now get the error "ImportError: No module named rospkg". Thanks for your help.

Comment by gvdhoorn on 2018-05-12:
Could you please describe how you installed ROS? You still haven't answered that question.

Also: what do you mean exactly with "set up a new environment with python 2.7.15 and reinstalled all dependencies"? Are you using virtualenv with pip?

Comment by jmm2270 on 2018-05-12:
So I installed ROS using sudo apt-install directly following directions from the ROS tutorial. I was trying a virtual env with anaconda. I just decided it may be easier to setup a new VM with virtual box using Ubuntu 16.04. My end goal is to simply process rosbags from an AV using python.

Comment by jmm2270 on 2018-05-12:
My question is now: if I start from scratch with a fresh install of Ubuntu, do I need to install python before ROS? Does the ROS full install include all the libraries I need to read from rosbags in python? I will be editing with sublime text. Thanks!

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

So I installed ROS using sudo apt-install directly following directions from the ROS tutorial.

Ok. That should install Python 2.7 (on Ubuntu 16.04) as well (if it wasn't already installed). All (well, most) ROS Python packages are only released for Python 2.

I was trying a virtual env with anaconda.

Ah. That will potentially complicate things. There are plenty of Q&A's on ROS Answers about Anaconda and the ROS Python packages.

If you're just starting out, you may want to focus on getting the basics working first, before trying to use 'alternative' Python interpreters.

I just decided it may be easier to setup a new VM with virtual box using Ubuntu 16.04. My end goal is to simply process rosbags from an AV using python.

I'm not sure what an 'AV' is, but I don't think you'll need to create a new virtual machine. Just remove Anaconda from your PATH and use the system default python (v2). That should work immediately.

My question is now: if I start from scratch with a fresh install of Ubuntu, do I need to install python before ROS?

No. The Ubuntu package manager (apt) will resolve those dependencies on its own. It'll install the regular Python 2 for you, if that isn't already present on your system.

Does the ROS full install include all the libraries I need to read from rosbags in python?

Typically, yes. Especially if you do a "desktop full" install.

I will be editing with sublime text.

The editor you'll be using does not influence any of this.

set up a new environment with python 2.7.15 and reinstalled all dependencies (I think),

If with 'setup a new environment' you mean a new 'virtualenv' and with "(re)installed all dependencies" you mean you used pip to install a nr of ROS Python pkgs then that can work, but you have to keep in mind that anything you install using pip will not be automatically considered for updates whenever those are released (ie: your package manager (apt) will not know those are installed). In general using pip to install ROS Python packages is not something that is recommended on platforms where binaries are available (it does work though).


Originally posted by gvdhoorn with karma: 86574 on 2018-05-12

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by jmm2270 on 2018-05-12:
Ah, ok, this all makes sense. I created a brand new virtualmachine running Ubuntu and I will just go through the standard install tutorial. I managed to mess up some other things while trying to fix my ptoblems. I will report back later today and mark this as the correct answer if I'm good. Thanks!

Comment by jmm2270 on 2018-05-13:
All is working now, thanks! AV stands for autonomous vehicle :)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.