ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

ImportError: No module named rospy

asked 2016-01-06 18:59:36 -0600

djsw gravatar image

When I roslaunch my node, the error I receive is

ImportError: No module named rospy

But when I open up the python environment and run import rospy, it imports successfully and I can access rospy.__file__, which returns


which is on my PYTHONPATH:

declare -x PYTHONPATH="/usr/lib/python2.7/dist-packages:/home/<user>/indigo_ws/devel/lib/python2.7/dist-packages:/opt/ros/indigo/lib/python2.7/dist-packages"

I do have a custom installation of Python that seems to have messed up some catkin_pkg installation, which is why it's had to be appended to the path. When I remove it to run roslaunch as a debug, I just get the same error.

Running Ubuntu 14.04 on a Raspberry Pi, if that helps.

edit retag flag offensive close merge delete


Did you check PYTHONPATH in os.environ? What version of the python interpreter is started by roslaunch?

Humpelstilzchen gravatar image Humpelstilzchen  ( 2016-01-08 00:00:33 -0600 )edit

3 Answers

Sort by ยป oldest newest most voted

answered 2016-01-08 00:52:52 -0600

djsw gravatar image

I worked out what the problem was.

I wanted access to the Raspberry Pi GPIO ports, so I had used launch-prefix="sudo" in my launch file. What this meant was that the file was launched in the root workspace which wasn't set up to use ROS. There is apparently a workaround that I wasn't able to get to work.

So my problem was solved by removing that from the launch file.

In case anybody finds this on google, I can use the GPIO ports in a ROS node by running pigpio. Some googling will produce an example script but this is either out-of-date or wrong - use the examples on the site.

edit flag offensive delete link more


The pigpio library really made my day! It's working beautifully and I can even control the raspberry gpio pins from a remote machine. (Ubuntu on both machines, ROS running either on both of them or the remote machine only, no "sudo node" involved.)

Falko gravatar image Falko  ( 2016-03-16 04:38:34 -0600 )edit

answered 2017-03-01 10:02:14 -0600

Yoan gravatar image

For those who still want to run a node as root despite the GPiO workaround hereabove, you must preserve the right environment variable: launch-prefix="sudo -E PYTHONPATH=$(env PYTHONPATH)"

edit flag offensive delete link more


I love you, thank you sooooo much!! :)

bjajo gravatar image bjajo  ( 2020-11-25 15:17:59 -0600 )edit

answered 2016-01-08 03:26:12 -0600

another option for pi gpio with ROS is to use the latest version of raspbian as that has gpio access without needing root enabled.

You need to build ROS from source, so it is better if you only need basic ROS functionality.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2016-01-06 18:59:36 -0600

Seen: 16,669 times

Last updated: Jan 08 '16