Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Try rosrun a python file, Got "ImportError: No module named yaml"

$
0
0

I'm trying to rosrun my python file, but it showed

$ rosrun forklift seg.pyTraceback (most recent call last):  File "/home/rvl224/brian2lee/gazebo/forklift_test/src/ros1_wiki/forklift/script/seg.py", line 3, in <module>    import rospy   File "/opt/ros/noetic/lib/python3/dist-packages/rospy/__init__.py", line 47, in <module>    from std_msgs.msg import Header  File "/opt/ros/noetic/lib/python3/dist-packages/std_msgs/msg/__init__.py", line 1, in <module>    from ._Bool import *  File "/opt/ros/noetic/lib/python3/dist-packages/std_msgs/msg/_Bool.py", line 6, in <module>    import genpy  File "/opt/ros/noetic/lib/python3/dist-packages/genpy/__init__.py", line 34, in <module>    from . message import Message, SerializationError, DeserializationError, MessageException, struct_I  File "/opt/ros/noetic/lib/python3/dist-packages/genpy/message.py", line 48, in <module>    import yamlImportError: No module named yaml

So I tried to install pyyaml and it told me I've already installed it

$ pip install pyyamlRequirement already satisfied: pyyaml in /usr/lib/python3/dist-packages (5.3.1)

Also tried methods found in other questions like 'pip3.x install pyyaml' or 'pip-3.x install pyyaml', but showed "no such command".
Here are my environments, seg.py & its location

ubuntu 20.04
ros noetic
vscode python 3.8.10
PyYAML 5.3.1
pyaml 23.12.0

/home/rvl224/brian2lee/gazebo/forklift_test/src/ros1_wiki/forklift/script/seg.py

#!/usr/bin/env python import rospy from sensor_msgs.msg import Imagefrom cv_bridge import CvBridgeclass BasicSubscriber:     def __init__(self):         # initialize the subscriber node         self.image_sub = rospy.Subscriber("/camera/color/image_raw",                                           Image, self.callback)         self.bridge = CvBridge()    def callback(self, data):         try:            # Convert ROS Image message to OpenCV image            cv_image = self.bridge.imgmsg_to_cv2(data, "bgr8")            rospy.loginfo("Received image")            print('Callback executed!')         except Exception as e:            rospy.logerr(e)def main():     # initializing the ROS node    rospy.init_node('listener', anonymous=True)     # create a subscriber instance     sub = BasicSubscriber()     rospy.spin() if __name__ == '__main__':     try:         main()     except rospy.ROSInterruptException:         pass

Edit: So the problem might be there's pyyaml in my /usr/lib/python3/dist-packages, but the code is trying to import it from /opt/ros/noetic/lib/python3/dist-packages. Is there a way to installed pyyaml into /opt/ros/noetic/lib/python3/dist-packages, or make the code look for pyyaml in /usr/lib/python3/dist-packages?


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>