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

To execute modules as scripts in Catkin

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

130s gravatar image

updated 2022-09-09 15:24:03 -0500

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

For instance, if you look at moveit_joy.py 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 
/opt/ros/indigo/share/moveit_ros_visualization

$ rosrun moveit_ros_visualization moveit_joy.py
[rosrun] Couldn't find executable named moveit_joy.py 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/moveit_joy.py
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/setup.py 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?

UPDATE 2022/09/07 Years later I came to my own post again. While this thread doesn't provide much reasoning for "Why is it bad?", sounds like encouraging re-use-ability by separating module and executable can be a propelling reason. See #q222258

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

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
1

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

Comments

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

Question Tools

1 follower

Stats

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

Seen: 759 times

Last updated: Sep 09 '22