ROS Resources: Documentation | Support | Discussion Forum | Service Status | Q&A
Ask Your Question

ImportError: No module named rospkg

asked 2012-07-24 05:11:17 -0500

Zara gravatar image

updated 2018-12-30 09:48:30 -0500

130s gravatar image

Hello All,

After installing ROS on my Ubuntu, I was trying to follow the tutorials under the simulator_gazebo. But I have gotten an error message for this command:

rosrun gazebo spawn_model -file `pwd`/object.urdf -urdf -z 1 -model my_object

Error message:

ImportError: No module named rospkg

Could it be from the installation? I think everything went well during the installation.

Any thoughts?


edit retag flag offensive close merge delete


Did you install Electric or Fuerte?

Lorenz gravatar imageLorenz ( 2012-07-24 05:42:15 -0500 )edit

I followed instruction through this link I guess it is Fuerte.

Zara gravatar imageZara ( 2012-07-24 05:54:56 -0500 )edit

7 Answers

Sort by » oldest newest most voted

answered 2017-03-01 14:41:33 -0500

130s gravatar image

updated 2019-02-01 12:21:11 -0500

The accepted answer (as of Feb 2017) is outdated. Unless you need to customize, using binary is strongly recommended IMO. See the instruction on ros wiki for how to install.

UPDATE 2019-02-02: Looks like this is still a popular question. apt worked for 18.04 for me on a docker container that I just pulled from online.

$ docker pull ros:melodic-ros-core
melodic-ros-core: Pulling from library/ros
Digest: sha256:206a3a506cda320b525ef2cf2587726ee01451f470be4dfdd80cd20693840f27
Status: Image is up to date for ros:melodic-ros-core
$ docker run -it ros:melodic-ros-core /bin/bash

# apt-get purge python-rospkg && apt-get update && apt-get install -y ipython python-rospkg
Unpacking python-rospkg (1.1.7-100) ...
Setting up python-rospkg (1.1.7-100) ...

root@4a5281183177:/# ipython
In [1]: import rospkg
In [2]: rp = rospkg.RosPack()
In [3]:
edit flag offensive delete link more



I've just made your answer the accepted one. Could you expand your answer with how users are expected to install binaries of rospkg?

gvdhoorn gravatar imagegvdhoorn ( 2017-03-01 15:01:35 -0500 )edit

Even with rospkg installed I still have the issue on Kubntu 18.04. Changing the PYTHONPATH variable solves the issue.

VictorLamoine gravatar imageVictorLamoine ( 2018-07-31 10:00:55 -0500 )edit

If you've installed everything from binaries and are using the system, default Python 2 installation, everything should-just-work. If it doesn't, and you have to change PYTHONPATH, something is wrong and you should resolve it. @130s answer is correct, and I don't think the downvote is justified.

gvdhoorn gravatar imagegvdhoorn ( 2018-07-31 12:22:34 -0500 )edit

@VictorLamoine I second to @gvdhoorn. Although I'm not sure how similar/same kubuntu is to any OSes ROS supports, any issues for the released binary must be fixed w/o adhoc workaround IMO. Maybe file at ros-infrastructure/rospkg.

130s gravatar image130s ( 2018-07-31 17:37:15 -0500 )edit

Even after installing via apt-get I am getting the same error. $ which python produces /home/userName/anaconda3/bin/python .

naveenk.medi gravatar imagenaveenk.medi ( 2018-09-05 06:40:36 -0500 )edit

@naveenk.medi Please open a new question with more detail.

130s gravatar image130s ( 2018-09-08 17:26:09 -0500 )edit

apt-get did not work for me on Ubuntu 18.04, pip install did. I think this answer would benefit from copy-pasting the instructions here, too.

fvd gravatar imagefvd ( 2019-01-31 02:17:26 -0500 )edit

answered 2016-04-15 04:24:01 -0500

sytelus gravatar image

The reason this error occurs is because Python packages in /opt are added to PYTHONPATH environment variable BUT for ones in /usr, path does not exist in PYTHONPATH variable. The python-rospkg gets installed in /usr by default. So you just need following line in .bashrc to fix this:

export PYTHONPATH=$PYTHONPATH:/usr/lib/python2.7/dist-packages
edit flag offensive delete link more


Hi :) I'm having issues because I'm using anaconda...I get an error because of the different PYTHONPATH used by anaconda. How can I use Anaconda with ROS?

Ahmed Abdalla gravatar imageAhmed Abdalla ( 2016-06-10 02:56:52 -0500 )edit

I have a same situation with @Ahmed Abdalla. The issue was solved by following this answer.

mark2n gravatar imagemark2n ( 2017-02-23 05:59:44 -0500 )edit

This answer worked for me in ROS Kinetic, Ubuntu 16.04. Thanks!

atp gravatar imageatp ( 2017-12-10 13:12:03 -0500 )edit

This made be encounter the error no module named _internal afterwards, that is, I couldn't use pip anymore.

nbro gravatar imagenbro ( 2019-03-02 14:58:43 -0500 )edit

answered 2017-01-18 19:44:31 -0500

pridanks gravatar image

I did pip install rospkg since I have anaconda. It worked.

(as a side note, for some packages I also got "No module named Em", for which I used pip install empy)

edit flag offensive delete link more


Thank you,It's useful for me. I am trying to build the turtlebot_rapps.

kun gravatar imagekun ( 2017-03-23 09:40:19 -0500 )edit

Worked for me. I installed rospkg and catkin_package via pip

aniket0112 gravatar imageaniket0112 ( 2018-04-09 13:51:00 -0500 )edit

answered 2012-08-05 22:39:59 -0500

michikarg gravatar image

updated 2012-08-05 22:51:32 -0500


since Fuerte, rospkg is standalone, so you will have to install it seperately e.g. by source:

$ git clone git:// $ python install --user

edit flag offensive delete link more


Ok, that worked! Thanks!

endamaco gravatar imageendamaco ( 2012-08-05 22:45:53 -0500 )edit

If you have added the ros sources you can apt-get install python-rospkg

tfoote gravatar imagetfoote ( 2012-08-06 15:46:39 -0500 )edit

Can you be more clearer? What worked well, I have the same problem

Markus Bader gravatar imageMarkus Bader ( 2012-08-20 02:02:16 -0500 )edit

I am also interested in your solution. I have a similar question here: . I have used the solution suggested here: install rospkg, but that does not suffice for me.

Shanker gravatar imageShanker ( 2012-09-27 03:33:03 -0500 )edit

answered 2012-07-26 14:37:07 -0500

Zara gravatar image

I am posting the entire message. Also version of python on my system is 2.7.1. Any help?

rosrun gazebo spawn_model Traceback (most recent call last): File "/opt/ros/fuerte/stacks/simulator_gazebo/gazebo/scripts/spawn_model", line 7, in <module> import roslib, time File "/opt/ros/fuerte/lib/python2.7/dist-packages/roslib/", line 50, in <module> from roslib.launcher import load_manifest File "/opt/ros/fuerte/lib/python2.7/dist-packages/roslib/", line 42, in <module> import rospkg ImportError: No module named rospkg

edit flag offensive delete link more

answered 2012-08-05 22:20:28 -0500

endamaco gravatar image

updated 2012-08-05 22:56:09 -0500

Same here, with ros fuerte on ubuntu 11.10 and python 2.7.3 .. The problem appears after last updates from repository.. I'm having the issue while compiling my package.. Last week all was fine, from this morning no

edit flag offensive delete link more

answered 2013-01-08 09:18:33 -0500

michikarg solution worked. People who have installed both versions of python 2.6 and 2.7 should do the following

$ git clone git:// $ cd rospkg $ python2.6 install --user

edit flag offensive delete link more


error: unknown option `user' usage: git clone [options] [--] <repo> [

] -v, --verbose be more verbose -q, --quiet be more quiet --progress force progress reporting -n, --no-checkout don't create a checkout --bare create a bare repository --mirror create a mirror repository (implies bare) -l, --local to clone from a local repository --no-hardlinks don't use local hardlinks, always copy -s, --shared setup as shared repository --recursive initialize submodules in the clone --recurse-submodules initialize submodules in the clone --template <template-directory> directory from which templates will be used --reference <repo> reference repository -o, --origin <name> use <name> instead of 'origin' to track upstream -b, --branch <branch> checkout <branch> instead of the remote's

FuerteNewbie gravatar imageFuerteNewbie ( 2013-10-02 16:55:48 -0500 )edit

What is wrong with the 'user' ?

FuerteNewbie gravatar imageFuerteNewbie ( 2013-10-02 16:56:01 -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: 2012-07-24 05:11:17 -0500

Seen: 32,779 times

Last updated: Feb 01