0
$\begingroup$

Rosanswers logo

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

/opt/ros/indigo/lib/python2.7/dist-packages/rospy/__init__.pyc

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.


Originally posted by djsw on ROS Answers with karma: 153 on 2016-01-06

Post score: 0


Original comments

Comment by Humpelstilzchen on 2016-01-08:
Did you check PYTHONPATH in os.environ? What version of the python interpreter is started by roslaunch?

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

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.


Originally posted by djsw with karma: 153 on 2016-01-08

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by Falko on 2016-03-16:
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.)

$\endgroup$
0
$\begingroup$

Rosanswers logo

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)"


Originally posted by Yoan with karma: 31 on 2017-03-01

This answer was NOT ACCEPTED on the original site

Post score: 3


Original comments

Comment by bjajo on 2020-11-25:
I love you, thank you sooooo much!! :)

$\endgroup$

Your Answer

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