0
$\begingroup$

Rosanswers logo

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


Originally posted by 130s on ROS Answers with karma: 10937 on 2016-01-19

Post score: 0

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

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


Originally posted by William with karma: 17335 on 2016-06-23

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$
0
$\begingroup$

Rosanswers logo

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


Originally posted by joq with karma: 25443 on 2016-02-08

This answer was NOT ACCEPTED on the original site

Post score: 1


Original comments

Comment by 130s on 2016-06-23:
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?

$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.