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 -0500

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 -0500 )edit

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

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

Backtrace of what exactly?

raymachira gravatar image raymachira  ( 2012-08-13 02:39:12 -0500 )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 -0500 )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 -0500 )edit

Sure. Here it is:

raymachira gravatar image raymachira  ( 2012-08-13 05:58:54 -0500 )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 -0500 )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 -0500 )edit

Thanks Lorenz. I have added these changes. I hope they are helpful.

raymachira gravatar image raymachira  ( 2012-08-13 07:29:44 -0500 )edit

The pythonpath should just be: /opt/ros/electric/ros/core/roslib/src, but having many of those does not hurt. Can you also execute ls /opt/ros/electric/ros/core/roslib/src and post the results in your question, please?

KruseT gravatar image KruseT  ( 2012-08-13 08:19:35 -0500 )edit

Sure. I have done so KruseT

raymachira gravatar image raymachira  ( 2012-08-13 08:28:22 -0500 )edit

This does not make much sense. Also post ls /opt/ros/electric/ros/core/roslib/src/roslib/*.py

KruseT gravatar image KruseT  ( 2012-08-13 08:40:59 -0500 )edit

Can you please not use cites but code blocks for code? Just copy-paste text, mark it and press Ctrl-k. That way, we don't lose any line breaks that might be important. Can you also post the output of the following entered in a python shell: import sys; sys.path

Lorenz gravatar image Lorenz  ( 2012-08-13 08:43:57 -0500 )edit

The path /opt/ros/electric/ros/core/roslib/src is missing from your sys.path. It should be in there if it was in your PYTHONPATH, unless what you do changes the PYTHONPAT or sys.path before you call import roslib.

KruseT gravatar image KruseT  ( 2012-08-13 10:04:31 -0500 )edit

I called as you said I should, and the roslib directory exists. I still get the same error.

raymachira gravatar image raymachira  ( 2012-08-13 10:26:50 -0500 )edit
1

Can you tell us more about what you do to get the error? Do you call a shell script, or a python script? What are the first line of the python script? What is the result of : $ cd /opt/ros/electric/ros/core/roslib/src;python -c 'import roslib; print "success"'

KruseT gravatar image KruseT  ( 2012-08-13 10:39:22 -0500 )edit

I have added this information.

raymachira gravatar image raymachira  ( 2012-08-14 02:04:22 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
9

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

KruseT gravatar image

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

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 -0500

Seen: 13,418 times

Last updated: Aug 17 '12