Ask Your Question

To execute modules as scripts in Catkin

asked 2016-01-19 18:58:50 -0500

130s gravatar image

updated 2016-06-23 12:33:35 -0500

Is there a way to run installed python modules as scripts in Catkin?

For instance, if you look at source from moveit_ros_visualization package, there are python files that contain classes (e.g. this) as well as main (if __name__ == "__main__":), which tells me it's intended as both module and script.

$ dpkg -p ros-indigo-moveit-ros-visualization | grep Ver
Version: 0.6.5-0trusty-20160114-1001-+0000
$ rospack find moveit_ros_visualization 

$ rosrun moveit_ros_visualization
[rosrun] Couldn't find executable named below /opt/ros/indigo/share/moveit_ros_visualization

# This module is callable as an argument for python interpreters. E.g.:
$ ipython /opt/ros/indigo/lib/python2.7/dist-packages/moveit_ros_visualization/
Unable to register with master node [http://localhost:11311]: master may not be running yet. Will keep trying.

(For the particular package above, because the module installed via distutils/ is not callable, it's worked around by defining install rule in CMakeLists.txt, which works fine but now we have duplicate python files in the installed space.)

Update 6/23/2016 To execute modules as scripts, should I install python file as script, or module in Catkin?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2016-06-23 14:01:09 -0500

William gravatar image

No, you should not use that to install a module. I wouldn't mess with executing a module with a main section, instead just write a small wrapper script which imported the module and runs the main, then install it with catkin_install_python()

edit flag offensive delete link more

answered 2016-02-08 13:01:10 -0500

joq gravatar image

The recommended way to install an executable Python script uses the catkin_install_python() CMake command.

edit flag offensive delete link more


Thank you, I wasn't aware of catkin_install_python() macro. I added a question to my original post; is catkin_install_python() recommended for installing a module that can also be called as an executable?

130s gravatar image 130s  ( 2016-06-23 12:35:13 -0500 )edit

Your Answer

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

Add Answer

Question Tools

1 follower


Asked: 2016-01-19 18:58:50 -0500

Seen: 592 times

Last updated: Jun 23 '16