Ask Your Question

Module not found error with rospkg when trying to import roslib

asked 2019-07-17 07:49:16 -0500

microbot gravatar image


I have developed a custom control algorithm for mz robot in gazebo. Untile yesterday I used to use

roslaunch spider_gazebo spider_world.launch

to spawn the robot and load control configurations in gazebo and then in another terminal i used to export ROS_MASTER_URI and then use

rosrun spider_control

to run my custom python plugin. Until yesterday this was working well, but today when I tried to launch again `I am having the following error

    'Traceback (most recent call last):
   File "/home/microbot/catkin_ws/src/spider/spider_control/", line 5, in <module>
     import roslib
   File "/opt/ros/melodic/lib/python2.7/dist-packages/roslib/", line 50, in <module>
     from roslib.launcher import load_manifest
    File "/opt/ros/melodic/lib/python2.7/dist-packages/roslib/", line 42, in <module>
      import rospkg
    ModuleNotFoundError: No module named 'rospkg'

I have also tried the following command to check whether my python path is right or not ,


The output is


I can not understand whats causing this error. can any one please help me point out the reason. Thanks

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-07-20 15:56:02 -0500

microbot gravatar image

I believe I have found the answer. The python-rospkg i have instaled are from python 2.7 version. Every time I install them, they get installed directly in /usr/lib/python2.7/distro-package path. But my terminal is sourcing only my work space and ros path. Also the plugin I am trying to run is built with python3. Since the python-rospkg I have installed are for python2.7, I am having this error

The second error with tensorflow is because , I have installed tensorflow for python3 and when I manually set the python path to python2.7/distro-package, it can not find tensor flow and hence this enum error.

PS: careful when trying to install python3-rospkg, when performing binary instalation, it is automatically removing plenty of ros related python2.7 packages. Unfortunately major commands in ros like roslaunch, rosrun etc still use python2.7

edit flag offensive delete link more

Comments might be the best thread regarding Python 2 & 3 issues for ROS1, fyi.

130s gravatar image 130s  ( 2019-07-26 03:26:21 -0500 )edit

thank you for the heads up.

microbot gravatar image microbot  ( 2019-07-28 12:59:29 -0500 )edit

@microbot were you able to fix the issue? I'm facing the exact same problem. I would be thankful if you could guide me.

polykb gravatar image polykb  ( 2021-04-22 03:30:14 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2019-07-17 07:49:16 -0500

Seen: 1,571 times

Last updated: Jul 20 '19