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
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)
Why are you running a simple Python script as
root
?@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
androslib.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.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
This is what I am getting now
Edit your original question. Don't post code updates / console text in a comment.
You haven't answered my initial question: why are you running a simple Python script using
sudo
?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.
Regular Python scripts containing
rospy
should not needsudo
. You'll have to tell us more about how you installed ROS, as that may give a clue.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.