justagist / franka_ros_interface

A ROS/Python API for controlling and managing the Franka Emika Panda robot (real and simulated).
http://justagist.github.io/franka_ros_interface
Apache License 2.0
171 stars 59 forks source link

Fix shebang for python2 and python3 compatibility #31

Closed matteolucchi closed 3 years ago

matteolucchi commented 3 years ago

Hello @justagist ! I hope you are doing fine :)

I wanted to directly make a pull request with this but I cannot due to time constraints :/ so I'll just give you a hint that I think you'll find useful.

If you use the shebang #!/usr/bin/env python at the top of your python scripts and add your python scripts in the CMakeList.txt like this for example:

catkin_python_setup()
catkin_install_python(PROGRAMS scripts/enable_robot.py 
                               scripts/move_to_neutral.py
                               scripts/simple_gripper.py
  DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})

like described here http://wiki.ros.org/UsingPython3/SourceCodeChanges

Then catkin will take care of replacing the shebang with the correct one and you can avoid

#!/bin/sh
''':'
if [ "$ROS_PYTHON_VERSION" = "3" ]; then
  exec python3 "$0" "$@"
else
  exec python2 "$0" "$@"
fi
'''

I hope this helps :)

justagist commented 3 years ago

Fantastic! That's just what I have been looking for! Thanks a lot for pointing me to this! I had already read the wiki in the link you shared; I cannot believe I forgot about that.

matteolucchi commented 3 years ago

It happens to me as well all the time :D I'm glad to hear it helped :)

justagist commented 3 years ago

I will probably not get a chance to work on this immediately either, so feel free to raise a PR if you get a chance before I do, and I will accept it. But don't worry if you can't. Thanks again! :smile:

matteolucchi commented 3 years ago

Sounds good :) I'll see if I manage to squeeze it in :)