我是ROS的新手,
当我在我的脚本文件example.py中导入rospy并运行它时,出现了问题:它显示:
Traceback (most recent call last):
File "/home/nagarjunv/hk_ws/src/rvo/src/example.py", line 4, in <module>
import rospy
File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/__init__.py", line 49, in <module>
from .client import spin, myargv, init_node, \
File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/client.py", line 52, in <module>
import roslib
File "/opt/ros/melodic/lib/python2.7/dist-packages/roslib/__init__.py", line 50, in <module>
from roslib.launcher import load_manifest # noqa: F401
File "/opt/ros/melodic/lib/python2.7/dist-packages/roslib/launcher.py", line 42, in <module>
import rospkg
ModuleNotFoundError: No module named 'rospkg'
我将下面的内容导入到我的脚本文件中: 第4行是rospy。
#!/usr/bin/env python3
import sys
import rospy
这是我的CMakeLists文件:
cmake_minimum_required(VERSION 3.0.2)
project(rvo)
find_package(catkin REQUIRED COMPONENTS
rospy
std_msgs
message_generation
)
generate_messages(
DEPENDENCIES
std_msgs
)
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES rvo
CATKIN_DEPENDS rospy std_msgs
# DEPENDS system_lib
)
include_directories(
# include
${catkin_INCLUDE_DIRS}
)
这是我的打包XML文件:
<buildtool_depend>catkin</buildtool_depend>
<build_depend>rospy</build_depend>
<build_depend>std_msgs</build_depend>
<build_depend>message_generation</build_depend>
<build_export_depend>rospy</build_export_depend>
<build_export_depend>std_msgs</build_export_depend>
<build_export_depend>message_generation</build_export_depend>
<exec_depend>rospy</exec_depend>
<exec_depend>std_msgs</exec_depend>
<exec_depend>message_runtime</exec_depend>
我在 CMakelists 和 Package XML 中都指定了 'rospy' 并导入了它。我也检查过我的 ROS 里有可用的 rospy 包。但是,我不明白为什么运行我的脚本文件时会遇到问题?
rosrun rvo example.py
我很乐意提供更多关于这个错误的细节。请问有人可以告诉我如何解决这个问题吗?