0
$\begingroup$

Rosanswers logo

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)

  2. catkin_create_pkg (run in SRC folder)

  3. Added scripts folder to the package folder

  4. Ran catkin_make (tired this step and left out but error is the same)

  5. Ran ". ~/ros_catkin_ws/devel/setup.bash" wile in catkin_ws folder because this seemed necessary based on what I read

  6. Used touch command to create python file

  7. Used chmod +x to make file executable

  8. Wrote python script that I copied from Udemy class (prints "Hello")

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

Originally posted by newbie77 on ROS Answers with karma: 26 on 2021-02-04

Post score: 0


Original comments

Comment by phillipov on 2021-02-04:
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.

Comment by jayess on 2021-02-04:
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

Comment by newbie77 on 2021-02-05:
Thank you! I was running Python 2. Also, I wan't sourcing the setup.bash every time I turned the Pi on.

Comment by jayess on 2021-02-05:
@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

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by newbie77 with karma: 26 on 2021-02-08

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by skpro19 on 2021-02-08:
Did you mean rospy needs python3?

Comment by newbie77 on 2021-02-08:
You are correct, I meant Python 3. Thank you for catching my typo.

Comment by skpro19 on 2021-02-08:
Welcome :-)

$\endgroup$

Your Answer

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