项目场景:
rosrun diagnostic_analysis export_csv.py
调用ros脚本进行数据分析
问题描述
脚本报错
Traceback (most recent call last):File "/opt/ros/noetic/lib/diagnostic_analysis/export_csv.py", line 40, in <module>import roslib; roslib.load_manifest(PKG)File "/opt/ros/noetic/lib/python3/dist-packages/roslib/__init__.py", line 50, in <module>from roslib.launcher import load_manifest # noqa: F401File "/opt/ros/noetic/lib/python3/dist-packages/roslib/launcher.py", line 42, in <module>import rospkg
ImportError: No module named rospkg
原因分析:
使用该ros命令调用脚本时,默认使用的是python,python默认链接的是python2,而rospkg一般需要python3,导致报错
解决方案:
cd /usr/bin
sudo ln -sf /usr/bin/python3.8 python
改软链接,使python默认调用python3