ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org
Ask Your Question
2

Do I have an error with rospy file tcpros_base.py?

asked 2020-12-26 13:21:04 -0500

gomesnelito gravatar image

Firstly, I'd like to pardon for any rookie mistakes as I am starting to learn how to work with ROS. While following the tutorials for a publisher in python using rospy, I attempted to run on my command line and the following error occured:

File "/home/nel/PycharmProjects/AutoMec-AD/ROS/src/automec_ros/scripts/talker.py", line 39, in <module>
    import rospy
File "/opt/ros/noetic/lib/python3/dist-packages/rospy/__init__.py", line 49, in <module>
    from .client import spin, myargv, init_node, \
File "/opt/ros/noetic/lib/python3/dist-packages/rospy/client.py", line 60, in <module>
    import rospy.impl.init
File "/opt/ros/noetic/lib/python3/dist-packages/rospy/impl/init.py", line 54, in <module>
    from .tcpros import init_tcpros
File "/opt/ros/noetic/lib/python3/dist-packages/rospy/impl/tcpros.py", line 45, in <module>
    import rospy.impl.tcpros_service
File "/opt/ros/noetic/lib/python3/dist-packages/rospy/impl/tcpros_service.py", line 54, in <module>
    from rospy.impl.tcpros_base import TCPROSTransport, TCPROSTransportProtocol, \
File "/opt/ros/noetic/lib/python3/dist-packages/rospy/impl/tcpros_base.py", line 160
    (e_errno, msg, *_) = e.args
                   ^
SyntaxError: invalid syntax

So, what can I do to solve this? Should I reinstall ROS or was this my mistake? I'm using ROS Noetic. Thank you for your attention.

edit retag flag offensive close merge delete

Comments

1

Did you manage to fix the error? I have the same error ...

nilooskh gravatar image nilooskh  ( 2020-12-30 04:28:20 -0500 )edit
1

Yes I did! Change the value on that file "/opt/ros/noetic/lib/python3/dist-packages/rospy/impl/tcpros_base.py" from (e_errno, msg, *_) = e.args to (e_errno, msg) = e.args

gomesnelito gravatar image gomesnelito  ( 2020-12-30 13:14:03 -0500 )edit

Hey, I tried doing that, however, I can't make changes to that file, it says I don't have permission to do that. Could you elaborate on how you did it? I opened it using gedit and tried to edit it

superipso gravatar image superipso  ( 2021-08-07 01:08:39 -0500 )edit

You need to use sudo before gedit command. So it'd be "sudo gedit tcpros_base.py"

habib muhammad thariq gravatar image habib muhammad thariq  ( 2022-02-18 21:16:35 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-08-07 06:55:39 -0500

gvdhoorn gravatar image

The problem is likely you're trying to execute Python 3 code with a Python 2 interpreter.

If /home/nel/PycharmProjects/AutoMec-AD/ROS/src/automec_ros/scripts/talker.py has /usr/bin/python as the shebang, and you have /usr/bin/python set to link to Python 2, this is the sort of error message you'd get.

Change the value on that file "/opt/ros/noetic/lib/python3/dist-packages/rospy/impl/tcpros_base.py" from (e_errno, msg, *_) = e.args to (e_errno, msg) = e.args

Do not edit files in non-world-writable locations.

tcpros_base.py is used by hundreds of thousands of people and machines. The chances of it causing an error like this which needs you to edit it locally on your machine are almost zero (as such an obvious problem would most likely have already been detected and fixed).

In general: if you believe you need to edit a file in /opt/ros: do not do it and search either for a proper solution or report a bug.

edit flag offensive delete link more

Comments

This was helpful.

To check if /usr/bin/python link to Python 2, run /usr/bin/python --version

To link to Python 3, run sudo ln -sf /usr/bin/python3 /usr/local/bin/python

fejj gravatar image fejj  ( 2021-09-07 09:03:48 -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

3 followers

Stats

Asked: 2020-12-26 13:21:04 -0500

Seen: 1,695 times

Last updated: Aug 07 '21