Setting up ROS and running the beginner tutorials on Ubuntu 16.04

This is the first in what I hope will be a series of posts, where I describe the installation procedures of software – stating the issues I faced and how I solved them.

Why? Because Linux….and literally every other piece of open source software aimed at the scientific/engineering community. You can only reinstall them a few times before you realize you should actually write down how you circumvented those same old bugs.

So first ROS.

Note: I believe most of these errors could have been avoided had I simply commented out Anaconda’s path in ~/.bashrc before beginning the installation

In installing ROS (Kinetic) on Ubuntu 16.04, I followed the instructions here for the Full desktop install. It was flawless.

After following the installation procedure stated at

http://wiki.ros.org/ROS/Tutorials/InstallingandConfiguringROSEnvironment

I proceeded to run

$ catkin_make

only to get the error

ImportError: "from catkin_pkg.package import parse_package" failed: No module named 'catkin_pkg'
Make sure that you have installed "catkin_pkg", it is up to date and on the PYTHONPATH.
CMake Error at /opt/ros/kinetic/share/catkin/cmake/safe_execute_process.cmake:11 (message):

So I checked the python path…

$ echo $PYTHONPATH
/opt/ros/kinetic/lib/python2.7/dist-packages

but knowing I had Anaconda with Python 3.5 installed, I checked to confirm which version was available

$ python
Python 3.5.2 |Anaconda custom (64-bit)

This implied installing catkin_pkg via apt-get would fail as it would be installed into Anaconda.

However, by using pip, I could install it into ROS’s python installation.

pip install catkin_pkg

With that cleared, catkin_make could run normally.


Continuing to the next tutorial, I tried to run rospack find, but got this

$ rospack find roscpp
$ [rospack] Unable to create temporary cache file /home/myusername/.ros/.rospack_cache.mnAamf: Permission denied

Taking ownership of the ~/.ros folder solved that.

sudo chown -R myusername ~/.ros 

Everything looked good with the subsequent tutorials till I had to run this in the Understanding ROS topics tutorial.

$ rosrun rqt_graph rqt_graph

Which returned

$ rosrun rqt_graph rqt_graph
Traceback (most recent call last):
  File "/opt/ros/kinetic/lib/rqt_graph/rqt_graph", line 5, in 
    from rqt_gui.main import Main
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/rqt_gui/main.py", line 38, in 
    import rospy
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/__init__.py", line 49, in 
    from .client import spin, myargv, init_node, \
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/client.py", line 52, in 
    import roslib
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/roslib/__init__.py", line 50, in 
    from roslib.launcher import load_manifest
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/roslib/launcher.py", line 42, in 
    import rospkg
ImportError: No module named 'rospkg'

Seemed easy…so I run pip

$ pip install rospkg

and got it installed, and run rqt_graph again…to get this

$ rosrun rqt_graph rqt_graph
Traceback (most recent call last):
  File "/opt/ros/kinetic/lib/rqt_graph/rqt_graph", line 8, in 
    sys.exit(main.main(sys.argv, standalone='rqt_graph.ros_graph.RosGraph'))
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/rqt_gui/main.py", line 59, in main
    return super(Main, self).main(argv, standalone=standalone, plugin_argument_provider=plugin_argument_provider, plugin_manager_settings_prefix=str(hash(os.environ['ROS_PACKAGE_PATH'])))
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/qt_gui/main.py", line 349, in main
    from .perspective_manager import PerspectiveManager
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/qt_gui/perspective_manager.py", line 44, in 
    class PerspectiveManager(QObject):
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/qt_gui/perspective_manager.py", line 48, in PerspectiveManager
    perspective_changed_signal = Signal(basestring)
NameError: name 'basestring' is not defined

It seemed like it had to do with my messy python setup. I considered fixing the basestring issue as it was a python 2 vs 3 compatibility issue. That brought up  another similar error and usually that’s a bad sign.

I gave up on a fixing that as it did not look critical, but thankfully I found out I could access the node graphs from rqt directly.

By running,

$ rqt

and heading to Plugins > Introspection > Node Graph, you could access the same functionality.

Also, in following the rqt_console tutorial, I had to run

$ rosrun rqt_console rqt_console

and

$ rosrun rqt_logger_level rqt_logger_level

…which could be replicated by running rqt like stated earlier, and going to Plugins > Logging > Console and also Plugins > Logging > Logger level

Alternatively, running

$ rqt_graph &

or

$ rqt_console &

or

$ rqt_logger_level &

works just as well.

I would be using that ad-hoc fix till cracks in this approach surface and probably prompt a full installation of ROS and possibly Python/Anaconda.


In running the tutorial on messages and services, my attempts to run catkin_make install failed with this

Traceback (most recent call last):
  File "/opt/ros/kinetic/share/gencpp/cmake/../../../lib/gencpp/gen_cpp.py", line 41, in 
Traceback (most recent call last):
  File "/opt/ros/kinetic/share/gencpp/cmake/../../../lib/gencpp/gen_cpp.py", line 41, in 
    import genmsg.template_tools
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/genmsg/template_tools.py", line 39, in 
    import genmsg.template_tools
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/genmsg/template_tools.py", line 39, in 
    import em
ImportError: No module named 'em'
    import em
ImportError: No module named 'em'

Installing empy fixed that

$ pip install empy

References:

http://answers.ros.org/question/126471/cmake-failed-catkin_pkg/

http://ros-users.122217.n3.nabble.com/error-massage-with-rospack-td1406092.html

Also, consider reviewing this to get Anaconda to play nice with other python installations.

5 Comments

  1. So when all is said and done, can you use the Anaconda install of python to program ROS, or do you still have to revert to the system installed version whenever using ROS?

    I was thinking of putting a conditional variable in my .bashrc so that I could easily switch back and forth between the default system install of Python and Ananconda which I use for almost everything else.

    Like

  2. That could work.

    I believe with a bit of fiddling there’s a chance you could work with both. However, for my work, anaconda did not provide any extra advantages since I had the scipy stack installed, so taking it down was the quickest way out.

    Since Anaconda is your primary distribution, you could consider modifying the path variable in the setup.bash file in the devel folder of your catkin workspace – which you have to source in every terminal.
    That could work if you still manually source it, and haven’t added it to the .bashrc

    There’s some code here that could help
    https://unix.stackexchange.com/questions/108873/removing-a-directory-from-path/291611#291611

    Alternatively, you could go the route of defaulting to python and manually typing the path for anaconda when you need to use it. Converting that into a short environmental variable could reduce the keystrokes required.
    http://answers.ros.org/question/244644/conflict-with-ros-python-and-conda/

    Like

  3. My solution for RoS / Anaconda: whenever i want to use RoS, i comment in bash.rc the whole anaconda section before openng the bash terminal, so nothing is added to the $PATH variable. When i want to use anaconda again, i uncomment it.

    Like

Leave a comment