Robotics StackExchange | Archived questions

How to define a python version for ROS

I try to run the teleop node using cmd:

rosrun turtlebot3_teleop turtlebot3_teleop_key 

But I get an error

  File "/home/goszjacek/catkin_ws/src/turtlebot3/turtlebot3_teleop/nodes/turtlebot3_teleop_key", line 140
    print msg
            ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(msg)?

Python path is set to:

/home/goszjacek/catkin_ws/devel/lib/python2.7/dist-packages:/opt/ros/melodic/lib/python2.7/dist-packages

But anyway ROS tries to run the turtlebot3teleopkey with python3. How can I force ROS to use 2.7, or can I change it in the settings?

Asked by goszjacek on 2019-11-29 08:24:21 UTC

Comments

Always add your ROS Distro to your question to get more directed answer. Because ROS Kinetic supports only python 2.7 but there are ways to compile it with different version.

Asked by Gokul on 2019-11-30 17:29:21 UTC

If you run python --version which version is it using? Also check the shebang line at the beginning of the script (the line with #!/usr/bin/env python)

Asked by ejalaa12 on 2021-02-25 16:42:20 UTC

Answers

You can use this command

catkin build --cmake-args -DPYTHON_VERSION=2.7

For further reference, you can try out different solution posted here for this question

Asked by Gokul on 2019-11-30 17:33:07 UTC

Comments