ModuleNotFoundError: No module named 'rospkg'

查看python使用版本

python --version

或者

python -V

问题,在roalaunch一个launch文件时报错

Traceback (most recent call last):
  File "/home/cgp/catkin_ws/src/rbx1/rbx1_nav/nodes/runopencv.py", line 3, in 
    import rospy
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/__init__.py", line 49, in 
    from .client import spin, myargv, init_node, \
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/client.py", line 52, in 
    import roslib
  File "/opt/ros/melodic/lib/python2.7/dist-packages/roslib/__init__.py", line 50, in 
    from roslib.launcher import load_manifest
  File "/opt/ros/melodic/lib/python2.7/dist-packages/roslib/launcher.py", line 42, in 
    import rospkg
ModuleNotFoundError: No module named 'rospkg'

这个问题我之前也遇到过

[runopencv-10] process has died [pid 3585, exit code 1, cmd /home/cgp/catkin_ws/src/rbx1/rbx1_nav/nodes/runopencv.py __name:=runopencv __log:=/home/cgp/.ros/log/118c046c-26d0-11ea-87f8-80ce62d5dcf4/runopencv-10.log].
log file: /home/cgp/.ros/log/118c046c-26d0-11ea-87f8-80ce62d5dcf4/runopencv-10*.log

runopencv.py是我的一个运行opencv的代码

解决方案

因为ubuntu自带的是python2,但是实际用的是python3
所以现在bashrc文件里加

alias python=python3

保存后

source ~/.bashrc

下载rospkg

pip3 install rospkg

你可能感兴趣的:(ModuleNotFoundError: No module named 'rospkg')