解决 import rospy 时的报错 SyntaxError: invalid syntax

1. 问题

使用 rospy 时遇到报错 SyntaxError: invalid syntax

Traceback (most recent call last):
  File "rtsp_to_rostopic.py", line 4, in <module>
    import rospy
  File "/usr/local/miniconda3/envs/py2/lib/python2.7/site-packages/rospy/__init__.py", line 49, in <module>
    from .client import spin, myargv, init_node, \
  File "/usr/local/miniconda3/envs/py2/lib/python2.7/site-packages/rospy/client.py", line 60, in <module>
    import rospy.impl.init
  File "/usr/local/miniconda3/envs/py2/lib/python2.7/site-packages/rospy/impl/init.py", line 54, in <module>
    from .tcpros import init_tcpros
  File "/usr/local/miniconda3/envs/py2/lib/python2.7/site-packages/rospy/impl/tcpros.py", line 45, in <module>
    import rospy.impl.tcpros_service
  File "/usr/local/miniconda3/envs/py2/lib/python2.7/site-packages/rospy/impl/tcpros_service.py", line 54, in <module>
    from rospy.impl.tcpros_base import TCPROSTransport, TCPROSTransportProtocol, \
  File "/usr/local/miniconda3/envs/py2/lib/python2.7/site-packages/rospy/impl/tcpros_base.py", line 160
    (e_errno, msg, *_) = e.args
                   ^
SyntaxError: invalid syntax

2. 解决问题

参考连接:https://answers.ros.org/question/368457/do-i-have-an-error-with-rospy-file-tcpros_basepy/

修改报错文件 /usr/local/miniconda3/envs/py2/lib/python2.7/site-packages/rospy/impl/tcpros_base.py 其中 160 行即可

# (e_errno, msg, *_) = e.args 原文件内容
(e_errno, msg) = e.args

3. 备注:pip 安装 rospy

pip install --extra-index-url https://rospypi.github.io/simple/ rospy

你可能感兴趣的:(python)