Ask Your Question
0

Error when running python script with ProcessBuilder()- rospkg.common.ResourceNotFound: rosgraph

asked 2019-06-14 05:58:06 -0600

Cipek gravatar image

updated 2019-06-14 05:59:13 -0600

I want to run a python script with ProcessBuilder(). This is my code:

new ProcessBuilder().inheritIO().command("/usr/bin/python", System.getProperty("user.dir")+"/WebRoot/result.py").start();

And this is code in result.py file:

    #! /usr/bin/env python
    import sys
    sys.path.append('/opt/ros/indigo/lib/python2.7/dist-packages')
    import rospy

    rospy.init_node('test_node')

It works fine when I run it manually via the console, but the problem appears when the above ProcessBuilder tries to do it. I get such an error then:

Traceback (most recent call last):
  File "/home/osboxes/Documents/MyFirstXText/org.xtext.example.helloweb.web/WebRoot/result.py", line 20, in <module>
    rospy.init_node('test_node')
  File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/client.py", line 306, in init_node
    rospy.core.configure_logging(resolved_node_name)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/core.py", line 300, in configure_logging
    _log_filename = rosgraph.roslogging.configure_logging('rospy', level, filename=filename)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/rosgraph/roslogging.py", line 107, in configure_logging
    rosgraph_d = rospkg.RosPack().get_path('rosgraph')
  File "/usr/lib/python2.7/dist-packages/rospkg/rospack.py", line 203, in get_path
    raise ResourceNotFound(name, ros_paths=self._ros_paths)
rospkg.common.ResourceNotFound: rosgraph
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-11-26 04:05:02 -0600

DI gravatar image

updated 2019-11-26 04:07:07 -0600

gvdhoorn gravatar image

I happened to run across this problem. At first I am thinking the same thing as you: ros will work perfectly as long as the '/opt/ros/indigo/lib/python2.7/dist-packages' is added. I am trying to using systemd to run a python script and I got the same error as you did. But I was able to run it in console. I then find out ros has other environment setup not only the PYTHONPATH.

Environment="PYTHONPATH=/opt/ros/kinetic/lib/python2.7/dist-packages"
Environment="Environment="ROS_ROOT=/opt/ros/kinetic/share/ros"
Environment="ROS_PACKAGE_PATH=/opt/ros/kinetic/share"
Environment="LD_LIBRARY_PATH=/opt/ros/kinetic/lib:/opt/ros/kinetic/lib/x86_64-linux-gnu"
Environment="PATH=/opt/ros/kinetic/bin:/home/hd/bin:/home/hd/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
Environment="PYTHONPATH=/opt/ros/kinetic/lib/python2.7/dist-packages"
Environment="PKG_CONFIG_PATH=/opt/ros/kinetic/lib/pkgconfig:/opt/ros/kinetic/lib/x86_64-linux-gnu/pkgconfig"
Environment="CMAKE_PREFIX_PATH=/opt/ros/kinetic"
Environment="ROS_ETC_DIR=/opt/ros/kinetic/etc/ros"

For me, I get so many env variable if I run "env | grep ros". I then set the environment variable in systemd file and the problem is solved. I hope this will help.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2019-06-14 05:58:06 -0600

Seen: 266 times

Last updated: Nov 26 '19