无法导入 rospy,因为 ModuleNotFoundError:没有名为 'rospkg' 的模块



我开始使用ROS,我在环境和导入方面遇到了一些麻烦(我知道这很愚蠢)…基本上我不能在我的python文件中导入rospy库,这应该很简单。

#!/usr/bin/env python3
import rospy
from rosplan_knowledge_msgs.msg import KnowledgeItem
from rosplan_knowledge_msgs.srv import KnowledgeUpdateService, KnowledgeUpdateServiceRequest
class PlatformStatusHandler : 
def __init__(self, robot_id, energy_level, health_status, current_profile) -> None:
self.robot_id = robot_id
self.energy_level = energy_level
self.health_status = health_status 
self.current_profile = current_profile

def test_rosplan_db(self, ins_type, ins_name, update_type) : 

rospy.wait_for_service('/rosplan_knowledge_base/update')
knowledge_update_proxy = rospy.ServiceProxy('/rosplan_knowledge_base/update', KnowledgeUpdateService)
req = KnowledgeUpdateServiceRequest()
req.knowledge.knowledge_type = KnowledgeItem.INSTANCE
req.knowledge.instance_type = ins_type
req.knowledge.instance_name = ins_name
req.update_type = update_type
success = success and knowledge_update_proxy(req).success
(new_env) benjies@benjies-Precision-3571:~/Workspace_c/SoaR_pipeline$ python3 PlatformStatusHandler.py 
Traceback (most recent call last):
File "PlatformStatusHandler.py", line 3, in <module>
import rospy
File "/opt/ros/noetic/lib/python3/dist-packages/rospy/__init__.py", line 49, in <module>
from .client import spin, myargv, init_node, 
File "/opt/ros/noetic/lib/python3/dist-packages/rospy/client.py", line 52, in <module>
import roslib
File "/opt/ros/noetic/lib/python3/dist-packages/roslib/__init__.py", line 50, in <module>
from roslib.launcher import load_manifest  # noqa: F401
File "/opt/ros/noetic/lib/python3/dist-packages/roslib/launcher.py", line 42, in <module>
import rospkg
ModuleNotFoundError: No module named 'rospkg'

这是我正在处理的代码,但我不能超过第一行。这是我的ROS_PACKAGE_PATH的内容,如果这有任何帮助,也许我在这一级把事情搞砸了。

echo $ROS_PACKAGE_PATH
/home/benjies/ROSPlan_workspace/src/ROSPlan/rosplan:/home/benjies/ROSPlan_workspace/src/ROSPlan/rosplan_action_interface:/home/benjies/ROSPlan_workspace/src/ROSPlan/rosplan_dispatch_msgs:/home/benjies/ROSPlan_workspace/src/ROSPlan/rosplan_knowledge_msgs:/home/benjies/ROSPlan_workspace/src/ROSPlan/rosplan_dependencies:/home/benjies/ROSPlan_workspace/src/ROSPlan/rosplan_knowledge_base:/home/benjies/ROSPlan_workspace/src/ROSPlan/rosplan_planning_system:/home/benjies/ROSPlan_workspace/src/ROSPlan/rosplan_rqt:/home/benjies/ROSPlan_workspace/src/ROSPlan/rosplan_sensing_interface:/home/benjies/catkin_ws/src:/opt/ros/noetic/share

您可能没有在您正在使用的终端窗口中获取您的ROS安装目录。ROS不会自动执行此操作,以避免在安装了多个发行版时出现问题-请尝试以下内容:

# Source our ROS2 installation
source /opt/ros/humble/setup.bash
source ~/dev/ros2/install/setup.bash

每次你想在终端中运行ros代码,或者你可以把这些行添加到你的。bashrc文件中,如果你不介意它们总是被引用

相关内容

  • 没有找到相关文章

最新更新