Ask Your Question
0

SyntaxError in tcpros_base (Noetic, RPi, Python)

asked 2021-02-04 09:44:01 -0500

newbie77 gravatar image

updated 2021-02-08 08:38:56 -0500

gvdhoorn gravatar image

I am new to ROS and am probably making an obvious mistake. I am running Noetic on Raspberry Pi 4 and it appears to have installed correctly. Specifically, I am trying to build a very simple node (based on an UDemy class) and keep getting rospy issues (or at least I think rospy issues).

Here is an outline of what I have done. I have tried many permutations and continue to get the same error. 1. catkin_make (run in catkin WS folder)

  1. catkin_create_pkg (run in SRC folder)

  2. Added scripts folder to the package folder

  3. Ran catkin_make (tired this step and left out but error is the same)
  4. Ran ". ~/ros_catkin_ws/devel/setup.bash" wile in catkin_ws folder because this seemed necessary based on what I read
  5. Used touch command to create python file
  6. Used chmod +x to make file executable
  7. Wrote python script that I copied from Udemy class (prints "Hello")
  8. Get the following error:

Traceback (most recent call last):
  File "my_first_node.py", line 3, in <module>
    import rospy
  File "/home/pi/ros_catkin_ws/devel/lib/python3/dist-packages/rospy/__init__.py", line 34, in <module>
    exec(__fh.read())
  File "<string>", line 49, in <module>
  File "/home/pi/ros_catkin_ws/src/ros_comm/rospy/src/rospy/client.py", line 60, in <module>
    import rospy.impl.init
  File "/home/pi/ros_catkin_ws/src/ros_comm/rospy/src/rospy/impl/init.py", line 54, in <module>
    from .tcpros import init_tcpros
  File "/home/pi/ros_catkin_ws/src/ros_comm/rospy/src/rospy/impl/tcpros.py", line 45, in <module>
    import rospy.impl.tcpros_service
  File "/home/pi/ros_catkin_ws/src/ros_comm/rospy/src/rospy/impl/tcpros_service.py", line 54, in <module>
    from rospy.impl.tcpros_base import TCPROSTransport, TCPROSTransportProtocol, \
  File "/home/pi/ros_catkin_ws/src/ros_comm/rospy/src/rospy/impl/tcpros_base.py", line 160
    (e_errno, msg, *_) = e.args
                   ^
SyntaxError: invalid syntax

Below is my python script for the node:

#!/usr/bin/env python3

import rospy

if __name__ == '__main__':
    rospy.init_node('my_first_python_node')
    rospy.loginfo("This node has been started")
rate = rospy.Rate(10)

while not rospy.is_shutdown():
    rospy.loginfo("Hello")
    rate.sleep()
edit retag flag offensive close merge delete

Comments

1

ROS1 Noetic targets Python 3 instead of Python 2 (like previous ROS1 distros). Can you tell us the output of python --version and python3 --version on your Pi? The syntax error is giving me the hint that it's related to Python version issues.

phillipov gravatar image phillipov  ( 2021-02-04 17:24:15 -0500 )edit
2

Not an answer, but you may want to change the title of your question to something more descriptive. You'll probably get more replies that way

jayess gravatar image jayess  ( 2021-02-04 17:53:23 -0500 )edit
2

Thank you! I was running Python 2. Also, I wan't sourcing the setup.bash every time I turned the Pi on.

newbie77 gravatar image newbie77  ( 2021-02-05 08:46:10 -0500 )edit
1

@newbie77 you may want to write your solution up as an answer so that it can help others who may have the same problem in the future

jayess gravatar image jayess  ( 2021-02-05 19:45:21 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-02-08 07:05:48 -0500

newbie77 gravatar image

updated 2021-02-08 08:46:42 -0500

In case anyone else runs into this issue, my raspberry pi was running python2 and rospy needs python3, at least for Noetic. Thanks, jayess for encouraging me to post answer.

edit flag offensive delete link more

Comments

Did you mean rospy needs python3?

skpro19 gravatar image skpro19  ( 2021-02-08 08:29:53 -0500 )edit

You are correct, I meant Python 3. Thank you for catching my typo.

newbie77 gravatar image newbie77  ( 2021-02-08 08:32:43 -0500 )edit

Welcome :-)

skpro19 gravatar image skpro19  ( 2021-02-08 08:33:47 -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

Stats

Asked: 2021-02-04 09:44:01 -0500

Seen: 398 times

Last updated: Feb 08 '21