小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
-
我之前装过一次ros,但由于一些自己的失误(好像是和python有关的代码)导致roscore报错了,然后我把ros卸载了重新一键安装,但依旧报错,请教各位大神帮我看看应该如何解决。附上报错代码
roscore
Traceback (most recent call last):
File "/opt/ros/melodic/bin/roscore", line 37, in <module>
from roslaunch.nodeprocess import DEFAULT_TIMEOUT_SIGINT, DEFAULT_TIMEOUT_SIGTERM
File "/opt/ros/melodic/lib/python2.7/dist-packages/roslaunch/init.py", line 52, in <module>
from . import param_dump as roslaunch_param_dump
File "/opt/ros/melodic/lib/python2.7/dist-packages/roslaunch/param_dump.py", line 40, in <module>
import roslaunch.config
File "/opt/ros/melodic/lib/python2.7/dist-packages/roslaunch/config.py", line 45, in <module>
import rospkg.distro
File "/home/fzz/.local/lib/python2.7/site-packages/rospkg/distro.py", line 44, in <module>
import yaml
File "/usr/lib/python3/dist-packages/yaml/init.py", line 284
class YAMLObject(metaclass=YAMLObjectMetaclass):
^
SyntaxError: invalid syntax
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/init.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
from apport.packaging_impl import impl as packaging
File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 24, in <module>
import apt
File "/usr/lib/python3/dist-packages/apt/init.py", line 23, in <module>
import apt_pkg
ImportError: No module named apt_pkgOriginal exception was:
Traceback (most recent call last):
File "/opt/ros/melodic/bin/roscore", line 37, in <module>
from roslaunch.nodeprocess import DEFAULT_TIMEOUT_SIGINT, DEFAULT_TIMEOUT_SIGTERM
File "/opt/ros/melodic/lib/python2.7/dist-packages/roslaunch/init.py", line 52, in <module>
from . import param_dump as roslaunch_param_dump
File "/opt/ros/melodic/lib/python2.7/dist-packages/roslaunch/param_dump.py", line 40, in <module>
import roslaunch.config
File "/opt/ros/melodic/lib/python2.7/dist-packages/roslaunch/config.py", line 45, in <module>
import rospkg.distro
File "/home/fzz/.local/lib/python2.7/site-packages/rospkg/distro.py", line 44, in <module>
import yaml
File "/usr/lib/python3/dist-packages/yaml/init.py", line 284
class YAMLObject(metaclass=YAMLObjectMetaclass):
^
SyntaxError: invalid syntax -
-
@fuzz 多少的系统呀?默认的python版本是3吗
-
@小鱼 您好,我是u18.04,ros melodic,之前貌似是默认2,然后我根据网上教学一通瞎操作想搞成3,但是可能没有成功,所以之后roscore一直报错,我卸载后按照您的一键安装后依旧这样报错。
-
@fuzz 主要原因是默认的python版本造成的,需要改回python3
-
@小鱼 您好,可以向您请教一下要如何操作吗,我现在刚开始接触ros还不太懂,谢谢!
-
@fuzz 看你怎么改的默认的了,一般是改软链接,你要根据你改过去的方式反向操作下。
-
@小鱼您好,谢谢您的意见,我按您说的尝试一下,感谢!
-
@fuzz 好嘞,代码块可以用markdown包裹一下,安装相关问题在一键安装模块下提问即可。
-
@小鱼 您好,我按照以下方法成功修改了默认python版本
Linux Python 版本切换方法
切换python版本update-alternatives --display python
如果出现以下错误:
update-alternatives: 错误: 无 python 的候选项,那么按下面的流程操作。#查看多个python版本
#ls /usr/bin/python
python2.7 python3.6
#添加Python2可选项,优先级为2sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 2
#添加Python3可选项,优先级为1sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 1
#配置sudo update-alternatives --config python
#yongyu 删除配置sudo update-alternatives --remove python /usr/bin/python2.7
来源:https://www.csdn.net/tags/NtzaAgysNDA5NjQtYmxvZwO0O0OO0O0O.html
感谢您的指导,谢谢! -
@fuzz 客气,修改完再试试是否可以正常使用ROS
-
@小鱼 已经可以成功运行小乌龟了
-
-
@小鱼 @fuzz 按照帖子的内容修改了,又出现了下面的错误,请问大佬们怎么解决啊?谢谢~ (我的环境和fuzz的一样)
Traceback (most recent call last):
File "/opt/ros/melodic/bin/roscore", line 37, in <module>
from roslaunch.nodeprocess import DEFAULT_TIMEOUT_SIGINT, DEFAULT_TIMEOUT_SIGTERM
File "/opt/ros/melodic/lib/python2.7/dist-packages/roslaunch/init.py", line 39, in <module>
import rospkg
ModuleNotFoundError: No module named 'rospkg' -
解决了
pip3 install rospkg -
我装的python3可是也出现了这个问题
-
@gaoxu515 为什么这个我输入后报错
-
Traceback (most recent call last):
File "/usr/bin/roscore", line 37, in <module>
from roslaunch.nodeprocess import DEFAULT_TIMEOUT_SIGINT, DEFAULT_TIMEOUT_SIGTERM
File "/usr/lib/python3/dist-packages/roslaunch/init.py", line 62, in <module>
from .scriptapi import ROSLaunch
File "/usr/lib/python3/dist-packages/roslaunch/scriptapi.py", line 42, in <module>
import roslaunch.parent
File "/usr/lib/python3/dist-packages/roslaunch/parent.py", line 54, in <module>
import roslaunch.server
File "/usr/lib/python3/dist-packages/roslaunch/server.py", line 80, in <module>
from rosgraph_msgs.msg import Log
ImportError: cannot import name 'Log' from 'rosgraph_msgs.msg' (/opt/ros/rolling/lib/python3.10/site-packages/rosgraph_msgs/msg/init.py) -
@1412846703 ros2不需要输入rosroce来跑小乌龟,直接输入ros2 run turtlesim turtlesim_node
之后再开个命令行输入ros2 run turtlesim turtle_teleop_key就可以了。
详见 https://zhuanlan.zhihu.com/p/481084074#:~:text=启动小乌龟仿真器: ros2 run turtlesim turtlesim_node 启动后可以看到一个仿真器:,另外需要打开一个终端,在里面运行键盘控制的节点,命令如下: ros2 run turtlesim turtle_teleop_key 正如打印信息所述,可以通过键盘上的方向箭头移动小乌龟,可以通过G|B|V|C|D|E|R|T这些按键进行旋转到一个绝对的方向,F取消旋转,Q退出。