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

ImportError: No module named roslib

asked 2012-08-13 00:35:32 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

I am having a problem running python files. Here are the 1st-3rd lines of the py file:

#!/usr/bin/env python
import roslib; roslib.load_manifest('irobot_mudd')
import rospy

Whenever I run $ sudo python ml.py (ml.py being the python file in question)- as well as any other py file importing roslib, I get the error message:

Traceback (most recent call last):
  File "ml.py", line 2, in <module>
    import roslib; roslib.load_manifest('irobot_mudd')
ImportError: No module named roslib

If I run

$ python ml.py

I get the following back:

Traceback (most recent call last):
  File "ml.py", line 4, in <module>
    import cv_bridge
ImportError: No module named cv_bridge

My setup.sh file is as follows:

export ROS_ROOT=/opt/ros/electric/ros
export PATH=${ROS_ROOT}/bin:${PATH}
export PYTHONPATH=${ROS_ROOT}/core/roslib/src:${PYTHONPATH}
export ROS_PACKAGE_PATH=/opt/ros/electric/stacks 
if [ ! "$ROS_MASTER_URI" ] ; then export ROS_MASTER_URI=http://localhost:11311 ; fi

this is what my python path looks like:

echo $PYTHONPATH 
/opt/ros/electric/ros/core/roslib/src:/opt/ros/electric/ros/core/roslib/src:/opt/ros/electric/ros/core/roslib/src:/opt/ros/electric/ros/core/roslib/src:/opt/ros/electric/ros/core/roslib/src:/opt/ros/electric/ros/core/roslib/src:/opt/ros/electric/ros/core/roslib/src:/opt/ros/electric/ros/core/roslib/src:/opt/ros/electric/ros/core/roslib/src:/opt/ros/electric/ros/core/roslib/src:/opt/ros/electric/ros/core/roslib/src:/opt/ros/electric/ros/core/roslib/src:/opt/ros/electric/ros/core/roslib/src:/opt/ros/electric/ros/core/roslib/src:/opt/ros/electric/ros/core/roslib/src:/opt/ros/electric/ros/core/roslib/src:

Here is the result of ls /opt/ros/electric/ros/core/roslib/src:

package.cpp  ros  roslib

And the result of ls /opt/ros/electric/ros/core/roslib/src/roslib/*.py is:

/opt/ros/electric/ros/core/roslib/src/roslib/exceptions.py   /opt/ros/electric/ros/core/roslib/src/roslib/params.py
/opt/ros/electric/ros/core/roslib/src/roslib/genpy.py        /opt/ros/electric/ros/core/roslib/src/roslib/resources.py
/opt/ros/electric/ros/core/roslib/src/roslib/gentools.py     /opt/ros/electric/ros/core/roslib/src/roslib/rosenv.py
/opt/ros/electric/ros/core/roslib/src/roslib/__init__.py     /opt/ros/electric/ros/core/roslib/src/roslib/roslogging.py
/opt/ros/electric/ros/core/roslib/src/roslib/launcher.py     /opt/ros/electric/ros/core/roslib/src/roslib/rospack.py
/opt/ros/electric/ros/core/roslib/src/roslib/manifestlib.py  /opt/ros/electric/ros/core/roslib/src/roslib/rostime.py
/opt/ros/electric/ros/core/roslib/src/roslib/manifest.py     /opt/ros/electric/ros/core/roslib/src/roslib/scriptutil.py
/opt/ros/electric/ros/core/roslib/src/roslib/message.py      /opt/ros/electric/ros/core/roslib/src/roslib/srvs.py
/opt/ros/electric/ros/core/roslib/src/roslib/msgs.py         /opt/ros/electric/ros/core/roslib/src/roslib/stack_manifest.py
/opt/ros/electric/ros/core/roslib/src/roslib/names.py        /opt/ros/electric/ros/core/roslib/src ...
(more)
edit retag flag offensive close merge delete

Comments

I have tried sourcing /opt/ros/electric/setup.sh While this command works, I still get the error

raymachira gravatar image raymachira  ( 2012-08-13 01:32:58 -0600 )edit

Please provide the complete backtrace. Maybe it contains something important.

Lorenz gravatar image Lorenz  ( 2012-08-13 02:18:01 -0600 )edit

Backtrace of what exactly?

raymachira gravatar image raymachira  ( 2012-08-13 02:39:12 -0600 )edit
1

The python backtrace that shows you the import error. Please always copy-paste the exact error you are getting. See http://www.ros.org/wiki/Support

Lorenz gravatar image Lorenz  ( 2012-08-13 03:40:31 -0600 )edit

Sure. Here it is:

raymachira gravatar image raymachira  ( 2012-08-13 05:58:54 -0600 )edit

Sure. Here it is: >>Traceback (most recent call last): >>File "ros_workspace/irobot_mudd/ml.py", line 2, in <module> >>import roslib; roslib.load_manifest('irobot_mudd') >>ImportError: No module named roslib

raymachira gravatar image raymachira  ( 2012-08-13 05:58:54 -0600 )edit

Could you please edit your original question and add it? That makes it way easier to read :)

Lorenz gravatar image Lorenz  ( 2012-08-13 06:02:49 -0600 )edit

Also, please execute echo $PYTHONPATH after you got the error, in the same terminal. Just to be sure your program uses the right path... :)

Lorenz gravatar image Lorenz  ( 2012-08-13 06:05:38 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
9

answered 2012-08-13 01:11:49 -0600

KruseT gravatar image

updated 2012-08-17 07:58:44 -0600

You need to call:

source /opt/ros/electric/setup.sh

either manually or in your .bashrc.

Check whether /opt/ros/electric/ros/core/roslib/src exists, and if not, run

sudo aptitude reinstall ros-electric-ros

EDIT: As Lorenz said, you should not use sudo. You should never ever ever use sudo, unless a tutorial tells you to.

So your only problem is:

import cv_bridge
ImportError: No module named cv_bridge

To import cv_bridge, cv_bridge must be listed in irobot_mudd/manifest.xml as

<depend package="cv_bridge"/>

Only then does roslib.load_manifest('irobot_mudd') put cv_bridge into the python path.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-08-13 00:35:32 -0600

Seen: 13,667 times

Last updated: Aug 17 '12