ROS Kinetic(Ubuntu16.04)运行项目遇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.bashThen install the required packages via apt:
sudo apt-get update sudo apt-get install ros-kinetic-mavros ros-kinetic-mavros-msgsAfter installation, re-source the ROS environment to pick up the new packages:
source /opt/ros/kinetic/setup.bashCheck 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 yourPYTHONPATH. Let's verify:
Run this command to see your current Python path:echo $PYTHONPATHLook for
/opt/ros/kinetic/lib/python2.7/dist-packagesin the output. If it's missing, add it temporarily to your current terminal:export PYTHONPATH=/opt/ros/kinetic/lib/python2.7/dist-packages:$PYTHONPATHTo make this change permanent (so you don't have to run it every time), add the above line to the end of your
~/.bashrcfile, then run:source ~/.bashrcVerify 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.msgIf 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

