1.操作步骤(我的环境:pycharm-community-2021.3.1,其他环境可作参考)
Pycharm
->Settings
->Project Interpreter
->Python Interpreter
->下三角
->show all
->点击选中你需要的python环境
->show path for project interpreter
->把ros路径导进去,把/opt/ros/melodic/lib/python2.7/dist-packages添加到python路径
->把~/catkin_ws/devel/lib/python2.7/dist-packages添加到python路径
2.添加路径原因
在保证正确配置package.xml和CMakelists.txt的基础上,创建ROS消息和服务
编译后,所有在msg路径下的.msg文件都将转换为ROS所支持语言的源代码
(1)生成的C++头文件将会放置在下面目录里面
~/catkin_ws/devel/include/beginner_tutorials/
(2)生成的Python脚本语言会在下面目录里面 ~/catkin_ws/devel/lib/python2.7/distpackages/beginner_tutorials/
因此要保证~/catkin_ws/devel/lib/python2.7/dist-packages/beginner_tutorials/msg被添加到$PYTHONPATH
3.欢迎大家批评交流!