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

ImportError: No module named rospkg

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

Zara gravatar image

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

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?

Thanks,

edit retag flag offensive close merge delete

Comments

Did you install Electric or Fuerte?

Lorenz gravatar image Lorenz  ( 2012-07-24 05:42:15 -0600 )edit

I followed instruction through this link http://www.ros.org/wiki/fuerte/Installation/Ubuntu. I guess it is Fuerte.

Zara gravatar image Zara  ( 2012-07-24 05:54:56 -0600 )edit

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/__init__.py", line 50, in <module> from roslib.launcher import load_manifest File "/opt/ros/fuerte/lib/python2.7/dist-packages/roslib/launcher.py", line 42, in <module> import rospkg ImportError: No module named rospkg

Zara gravatar image Zara  ( 2012-07-26 14:37:07 -0600 )edit
1

This can also happen if you are running the file with the wrong python interpreter. This might be the first thing you notice as import rospy is often the first import in a file. Not the problem here but this may be useful for others looking later

pjusesros gravatar image pjusesros  ( 2020-06-03 12:40:53 -0600 )edit
1

This should go as an edit to your original question.

KearaB gravatar image KearaB  ( 2020-06-17 17:22:45 -0600 )edit

thanks pjusesros. i forgot that i had set pyenv global python to be python3.8 after changing it to system python version everything worked fine. thanks for saving me from what otherwise was going to be a nightmare.

minhaj gravatar image minhaj  ( 2021-04-05 01:52:01 -0600 )edit

7 Answers

Sort by » oldest newest most voted
1

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

130s gravatar image

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

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

Comments

5

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 image gvdhoorn  ( 2017-03-01 15:01:35 -0600 )edit
1

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

VictorLamoine gravatar image VictorLamoine  ( 2018-07-31 10:00:55 -0600 )edit
2

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 image gvdhoorn  ( 2018-07-31 12:22:34 -0600 )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 image 130s  ( 2018-07-31 17:37:15 -0600 )edit

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

naveenk.medi gravatar image naveenk.medi  ( 2018-09-05 06:40:36 -0600 )edit
1

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

130s gravatar image 130s  ( 2018-09-08 17:26:09 -0600 )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 image fvd  ( 2019-01-31 02:17:26 -0600 )edit
16

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

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

Comments

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 image Ahmed Abdalla  ( 2016-06-10 02:56:52 -0600 )edit

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

mark2n gravatar image mark2n  ( 2017-02-23 05:59:44 -0600 )edit

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

atp gravatar image atp  ( 2017-12-10 13:12:03 -0600 )edit

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

nbro gravatar image nbro  ( 2019-03-02 14:58:43 -0600 )edit
15

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

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

Comments

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

kun gravatar image kun  ( 2017-03-23 09:40:19 -0600 )edit

Worked for me. I installed rospkg and catkin_package via pip

aniket0112 gravatar image aniket0112  ( 2018-04-09 13:51:00 -0600 )edit
10

answered 2020-10-10 08:18:06 -0600

fjp gravatar image

updated 2022-04-06 16:42:03 -0600

Update 06/04/2022:

When using Ubuntu 20.04, which uses python3 install python3-rospkg.


Previous (alternative) solution (not recommended anymore):

I am using ROS noetic on Ubuntu 20.04 which uses python3. To fix the error, in my case I had to install

sudo apt install python-is-python3

edit flag offensive delete link more

Comments

This worked for me, running noetic on Ubuntu 20.04.

arunj18 gravatar image arunj18  ( 2020-12-12 19:04:30 -0600 )edit

Great. This worked for me. Same problem with ROS noetic on Ubuntu 20.04

MiJi gravatar image MiJi  ( 2021-03-11 03:21:32 -0600 )edit

Yeah, it worked for me too. Here is an explanation of what it does

Anjulo gravatar image Anjulo  ( 2021-07-28 14:48:53 -0600 )edit

What you should rather do, is to install python3-rospkg. (I am using noetic on 20.04, and that is what I did.)

moooeeeep gravatar image moooeeeep  ( 2022-02-01 05:25:25 -0600 )edit
3

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

michikarg gravatar image

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

Hi,

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

$ git clone git://github.com/ros/rospkg.git $ python setup.py install --user

edit flag offensive delete link more

Comments

Ok, that worked! Thanks!

endamaco gravatar image endamaco  ( 2012-08-05 22:45:53 -0600 )edit

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

tfoote gravatar image tfoote  ( 2012-08-06 15:46:39 -0600 )edit
1

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

Markus Bader gravatar image Markus Bader  ( 2012-08-20 02:02:16 -0600 )edit
1

I am also interested in your solution. I have a similar question here: http://answers.ros.org/question/44669/fuerte-no-module-named-rospkg/ . I have used the solution suggested here: install rospkg, but that does not suffice for me.

Shanker gravatar image Shanker  ( 2012-09-27 03:33:03 -0600 )edit
0

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

endamaco gravatar image

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

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
0

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

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

$ git clone git://github.com/ros/rospkg.git $ cd rospkg $ python2.6 setup.py install --user

edit flag offensive delete link more

Comments

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 image FuerteNewbie  ( 2013-10-02 16:55:48 -0600 )edit

What is wrong with the 'user' ?

FuerteNewbie gravatar image FuerteNewbie  ( 2013-10-02 16:56:01 -0600 )edit

Question Tools

Stats

Asked: 2012-07-24 05:11:17 -0600

Seen: 131,367 times

Last updated: Apr 06 '22