You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ROS Kinetic(Ubuntu16.04)运行项目遇ImportError: No module named mavros_msgs.msg

解决ImportError: No module named mavros_msgs.msg的问题

Hey there, let's fix that ImportError: No module named mavros_msgs.msg issue you're hitting. The problem here is straightforward: even though you're running a TurtleBot script, the gym project you copied from the Docker container has hidden dependencies on the mavros_msgs package (part of the MAVROS stack for drone communication), and your local ROS Kinetic environment doesn't have this package installed yet.

Here's how to get this sorted out step by step:

  • Install the missing MAVROS packages
    First, make sure your ROS Kinetic environment is properly sourced (this should be in your .bashrc, but double-check):

    source /opt/ros/kinetic/setup.bash
    

    Then install the required packages via apt:

    sudo apt-get update
    sudo apt-get install ros-kinetic-mavros ros-kinetic-mavros-msgs
    

    After installation, re-source the ROS environment to pick up the new packages:

    source /opt/ros/kinetic/setup.bash
    
  • Check and fix your Python path
    Sometimes even after installing the package, Python can't find it because the ROS Python module directory isn't in your PYTHONPATH. Let's verify:
    Run this command to see your current Python path:

    echo $PYTHONPATH
    

    Look for /opt/ros/kinetic/lib/python2.7/dist-packages in the output. If it's missing, add it temporarily to your current terminal:

    export PYTHONPATH=/opt/ros/kinetic/lib/python2.7/dist-packages:$PYTHONPATH
    

    To make this change permanent (so you don't have to run it every time), add the above line to the end of your ~/.bashrc file, then run:

    source ~/.bashrc
    
  • Verify the fix before re-running your script
    Let's confirm the module is now accessible. Open a Python 2.7 shell (since ROS Kinetic uses Python 2.7) and try importing the module:

    import mavros_msgs.msg
    

    If you don't get any errors, you're good to go! Now re-run your TurtleBot script:

    python circuit2_turtlebot_lidar_qlearn.py
    

A quick heads-up: since you copied the entire project from a Docker container, there might be other missing dependencies down the line. If you hit similar ImportErrors for other ROS modules, just find the corresponding package name and install it with sudo apt-get install ros-kinetic-<package-name>.

内容的提问来源于stack exchange,提问作者Thong Chan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 09:01:16