1

I am attempting to use Google Colab to run https://github.com/ARiSE-Lab/deepTest deep neural network software developed on Ubuntu. I was able to run the install.sh with small modifications. I was successful, after adding "!", in loading:

! sudo apt-get install python-rosbag ! sudo apt-get install python-genmsg ! sudo apt-get install python-genpy ! sudo apt-get install python-rosgraph-msgs1 This installed many files including:

Setting up python-rosbag (1.13.5+ds1-3) ...

However, when I ran the program generate_hmb3.py whose 2nd line is:

import rosbag

I got an invalid syntax error message. When I changed the line to read:

import python-rosbag

I got the message:

  File "<ipython-input-12-37a7e266f3af>", line 7
import python-rosbag
             ^
SyntaxError: invalid syntax

Any solutions to this problem?

Lew Leibowitz
  • 55
  • 1
  • 8

2 Answers2

0

Import issue

Make sure you have your Python path set which should be done via the source command. You can easily check the correct path via

echo $PYTHONPATH
# which gives me
/opt/ros/kinetic/lib/python2.7/dist-packages

Importing modules with dashes:

Dashes are not allowed in python's import names (ref). And there isn't any standard module called python-rosbag. As far as I know, there is only rosbag. If it is your own written module, you can do that using __import__(). For example:

foobar = __import__("foo-bar")

But you really should rename the module instead.

Tik0
  • 2,499
  • 4
  • 35
  • 50
  • Thanks@Tik0. I did the following: – Lew Leibowitz Jul 24 '19 at 20:35
  • Thanks@Tik0. I did the following: ! which python. and got: /usr/local/bin/python. Then I asked: ! python --version Python 2.7.15+ . Then I asked: !find / -name "*rosbag*". And I got a lot including: /usr/lib/python2.7/dist-packages/rosbag /usr/lib/python2.7/dist-packages/rosbag/rosbag_main.py /usr/lib/python2.7/dist-packages/rosbag/rosbag_main.pyc – Lew Leibowitz Jul 24 '19 at 20:42
0

I tried a bunch of different things* and I think that this is an issue with ros still using python 2.7.

I actually couldn't get it to work as intended, but using https://github.com/event-driven-robotics/importRosbag worked for me.

* Like adding the paths from python2.7 and fiddling with importlib and imp. Couldn't get it to work; I get an error AttributeError: module 'rospy' has no attribute 'names'

user27221
  • 334
  • 3
  • 16