Please solve my error. sudo python image_converter.py [sudo] password for omkar: Traceback (most recent call last): File "image_converter.py", line 4, in <module> import roslib ImportError: No module named roslib

asked 2019-06-06 11:45:34 -0500

OSSome gravatar image

updated 2019-06-09 10:31:21 -0500

The code I tried to run:

#!/usr/bin/env python
from __future__ import print_function

import roslib
roslib.load_manifest('my_package')
import sys
import rospy
import cv2
from std_msgs.msg import String
from sensor_msgs.msg import Image
from cv_bridge import CvBridge, CvBridgeError

class image_converter:

  def __init__(self):
    self.image_pub = rospy.Publisher("image_topic_2",Image)

    self.bridge = CvBridge()
    self.image_sub = rospy.Subscriber("image_topic",Image,self.callback)

  def callback(self,data):
    try:
      cv_image = self.bridge.imgmsg_to_cv2(data, "bgr8")
    except CvBridgeError as e:
      print(e)

    (rows,cols,channels) = cv_image.shape
    if cols > 60 and rows > 60 :
      cv2.circle(cv_image, (50,50), 10, 255)

    cv2.imshow("Image window", cv_image)
    cv2.waitKey(3)

    try:
      self.image_pub.publish(self.bridge.cv2_to_imgmsg(cv_image, "bgr8"))
    except CvBridgeError as e:
      print(e)

def main(args):
  ic = image_converter()
  rospy.init_node('image_converter', anonymous=True)
  try:
    rospy.spin()
  except KeyboardInterrupt:
    print("Shutting down")
  cv2.destroyAllWindows()

if __name__ == '__main__':
    main(sys.argv)
edit retag flag offensive close merge delete

Comments

2

Why are you running a simple Python script as root?

gvdhoorn gravatar imagegvdhoorn ( 2019-06-06 13:26:03 -0500 )edit
1

@gvdhoorn asks a very good question, and points out a very likely cause to the issue you're experiencing. Also note, this first two "ROS" lines (import roslib and roslib.load_manifest) have not been needed for quite some time. Likely you are using an out-of-date example to build this script off of.

jarvisschultz gravatar imagejarvisschultz ( 2019-06-07 08:02:03 -0500 )edit

ossome@ubuntu:~/catkin_ws/src/beginner_tutorials/script$ python image_converter.py Traceback (most recent call last): File "image_converter.py", line 4, in <module> roslib.load_manifest('my_package') File "/opt/ros/kinetic/lib/python2.7/dist-packages/roslib/launcher.py", line 62, in load_manifest sys.path = _generate_python_path(package_name, _rospack) + sys.path File "/opt/ros/kinetic/lib/python2.7/dist-packages/roslib/launcher.py", line 93, in _generate_python_path m = rospack.get_manifest(pkg) File "/usr/lib/python2.7/dist-packages/rospkg/rospack.py", line 167, in get_manifest return self._load_manifest(name) File "/usr/lib/python2.7/dist-packages/rospkg/rospack.py", line 211, in _load_manifest retval = self._manifests[name] = parse_manifest_file(self.get_path(name), self._manifest_name, rospack=self) File "/usr/lib/python2.7/dist-packages/rospkg/rospack.py", line 203, in get_path raise ResourceNotFound(name, ros_paths=self._ros_paths) rospkg.co

OSSome gravatar imageOSSome ( 2019-06-08 03:28:06 -0500 )edit

This is what I am getting now

OSSome gravatar imageOSSome ( 2019-06-08 03:28:22 -0500 )edit
2

Edit your original question. Don't post code updates / console text in a comment.

gvdhoorn gravatar imagegvdhoorn ( 2019-06-08 04:49:56 -0500 )edit

You haven't answered my initial question: why are you running a simple Python script using sudo?

gvdhoorn gravatar imagegvdhoorn ( 2019-06-10 02:25:48 -0500 )edit

Actually I code on ROG Strix GL503, I was unable to install Ubuntu on it due to some problems. So instead I am using VMware. On VMware the code was not not getting extecuted with using sudo, so I used sudo. Please help me in installing Ubuntu on my laptop.

OSSome gravatar imageOSSome ( 2019-06-10 06:14:52 -0500 )edit

Regular Python scripts containing rospy should not need sudo. You'll have to tell us more about how you installed ROS, as that may give a clue.

Please help me in installing Ubuntu on my laptop.

I'm afraid this is not a generic Ubuntu support platform. You'll want to post requests of that type of Ask Ubuntu or the Ubuntu support fora.

gvdhoorn gravatar imagegvdhoorn ( 2019-06-10 06:49:38 -0500 )edit