AttributeError: module 'rosbag' has no attribute 'Bag'
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!
If you installed ROS using
apt
(orapt-get
) then there is no Python 3 support. But I would have expected theimport
to already fail.If you installed things in a different way, then please tell us how, as that is going to be important.
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.
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 usingapt-get
don't support Python 3.In addition: you have named your own script
rosbag.py
. That is not a good idea, as it will shadow (ie: hide) therosbag
that you're trying to use.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.
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
withpip
?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.
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!