ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Fail to import rospy

asked 2018-04-10 10:15:00 -0500

brunoribeiro gravatar image

updated 2018-04-10 10:53:41 -0500

gvdhoorn gravatar image

Hello Guys

I'm trying to implement a code to call ROS topics inside a Python code.

When i try to import rospy and roslib I have the message:

import roslib
ImportError: No module named roslib

my initial code is:

from collections import deque
import numpy as np
import argparse
import imutils
import cv2
import os # incluido para chamar comando do linux.
import time #incluido para utilizar o delay
import roslib
import rospy
from geometry_msgs.msg import Twist
edit retag flag offensive close merge delete


This is not a solution, but: you don't need to import roslib any longer in a rospy script. Unless you're using some functionality from it of course.

gvdhoorn gravatar image gvdhoorn  ( 2018-04-10 10:54:15 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2018-04-10 11:07:33 -0500

mgruhler gravatar image

You need to have the ROS Environment sourced in the terminal where you run this. Follow the tutorial about Setting up a ROS Workspace.

Remember to call source <PATH_TO_YOUR_WORKSPACE>/devel/setup.bash in every new terminal you open.

edit flag offensive delete link more


Or even better, writte down the source <PATH_TO_YOUR_WORKSPACE>/devel/setup.bash into your .bashrc file, which will source the setup file automatically everytime you open a new terminal.

kharkad gravatar image kharkad  ( 2018-04-11 07:22:21 -0500 )edit

@kharkad you are correct.

Though once you start working with multiple workspaces this can lead to a lot of confusion. Thus, until you know what this is about, I personally think it helps people understand what is required and why if you have to do that manually...

mgruhler gravatar image mgruhler  ( 2018-04-12 01:08:26 -0500 )edit

Question Tools

1 follower


Asked: 2018-04-10 10:13:23 -0500

Seen: 2,197 times

Last updated: Apr 10 '18