Ask Your Question

Start a node from python code - rospy equivalence rosrun - rosgui qt

asked 2012-08-20 01:54:39 -0500

clotz gravatar image

updated 2018-03-21 12:08:43 -0500

130s gravatar image


I'm writing a plugin for my rosgui in python. At the moment I'm trying to write an "pressed-button" action which starts a rosnode. I's there a python-command equivalent to "rosrun pkg node" or the launch-command "<node name="..." pkg="..." type="...">?

Unfortunately I couldn't find something in the documentations yet.

Thanks for Help.

edit retag flag offensive close merge delete

4 Answers

Sort by » oldest newest most voted

answered 2016-03-12 18:37:29 -0500

updated 2020-10-11 22:52:53 -0500

lucasw gravatar image

You can use the roslaunch api for python (ref):

import roslaunch

package = 'rqt_gui'
executable = 'rqt_gui'
node = roslaunch.core.Node(package, executable)

launch = roslaunch.scriptapi.ROSLaunch()

process = launch.launch(node)
edit flag offensive delete link more


@lucasw any idea how to rewrite this code in ROS2 foxy?

maciej-3 gravatar image maciej-3  ( 2021-02-03 18:53:11 -0500 )edit

answered 2012-09-08 16:28:23 -0500

jbohren gravatar image

As of now the internal roslaunch python API is unstable, but that doesn't mean you can't use it, it just means that there's no guarantee your code is going to continue to work.

Stu Glaser wrote a simple qt-based roslaunch frontend which can be found here: and this gives a simple example of how to do what roslaunch does via Python. (it also has some code taken from roslaunch itself)

If you want to start a node from Python, and want to be able to expect that it will continue to work, you could call out to rosrun with the Python subprocess module

Also, "rosrun" is just a bash script.

edit flag offensive delete link more



Any updates on this yet?

2ROS0 gravatar image 2ROS0  ( 2017-05-05 15:28:44 -0500 )edit

answered 2020-02-17 12:29:11 -0500

machinekoder gravatar image

Just use Popen:

import shlex
from psutil import Popen
# start
node_process = Popen(
    shlex.split('rosrun foo bar')
# stop
edit flag offensive delete link more


@machinekodernode_process.terminate() does not actually terminates nodes in ROS2 foxy. After the execution of this line of code, I can still see all the nodes in ros2 node list. Any idea how to fix that?

maciej-3 gravatar image maciej-3  ( 2021-02-03 18:59:59 -0500 )edit

answered 2012-09-08 14:31:54 -0500

130s gravatar image

Not entirely sure what you mean but I assume you've already checked rospy.init_node?

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


Asked: 2012-08-20 01:54:39 -0500

Seen: 9,169 times

Last updated: Oct 11 '20