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

How "ImportError: No module named rospkg" happens

asked 2018-02-17 03:37:20 -0600

130s gravatar image

updated 2019-03-29 11:51:10 -0600

This error is apparently FAQ on answers.ros.org . How does this even happen?

Traceback (most recent call last):
  File "/opt/ros/kinetic/share/xacro/xacro.py", line 55, in <module>
    import xacro
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/xacro/__init__.py", line 42, in <module>
    from roslaunch import substitution_args
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/roslaunch/__init__.py", line 48, in <module>
    import rospkg
ImportError: No module named rospkg

For those who seek immediate fix to this issue, you can install by either apt or pip as in this answer (although pip is not a first recommendation in ROS).

But that is only a workaround. rospkg is depended on by many packages as in the following example output, so I'm worried if there's anything we're missing. In a lot of cases users get this error while running roslaunch, which directly run_depend on it. So apparently if you didn't fulfill dependencies by like rosdep it wouldn't get installed, but then a lot of other packages wouldn't either so I don't even know how you could finish build.

$ docker images | grep -i kinetic-ros-core
ros                                                kinetic-ros-core    36be7bf1f0b9        3 weeks ago         926MB
$ docker run -it ros:kinetic-ros-core
root@57df7176d6bd:/# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.3 LTS
Release:        16.04
Codename:       xenial
root@57df7176d6bd:/# apt-cache rdepends python-rospkg
python-rospkg
Reverse Depends:
  python-rospkg-modules
  ros-kinetic-rosgraph
  ros-kinetic-rosclean
  ros-kinetic-roslib
  python-rosdep
  ros-kinetic-roscreate
  python-rospkg-modules
  ros-kinetic-roslaunch
  ros-kinetic-rosbag
  ros-kinetic-roswtf
  ros-kinetic-rospy
  ros-kinetic-rosmsg
  ros-kinetic-rosmake
  ros-kinetic-rosunit
root@57df7176d6bd:/# apt-cache policy ros-kinetic-rosgraph
ros-kinetic-rosgraph:
  Installed: 1.12.12-0xenial-20171116-185949-0800
  Candidate: 1.12.12-0xenial-20171116-185949-0800
  Version table:
 *** 1.12.12-0xenial-20171116-185949-0800 100
        100 /var/lib/dpkg/status
edit retag flag offensive close merge delete

Comments

1

The referenced question doesn't exist. And "blindly" recommending pip is not a good idea.

Dirk Thomas gravatar image Dirk Thomas  ( 2018-02-20 11:15:36 -0600 )edit

Anaconda installation raises this problem any solution?

Meric gravatar image Meric  ( 2019-03-29 06:42:38 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
3

answered 2018-02-20 11:17:18 -0600

Dirk Thomas gravatar image

In many cases this problem arises when users are using a non-default Python interpreter, e.g. anaconda which uses a different Python path.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2018-02-17 03:37:20 -0600

Seen: 6,601 times

Last updated: Mar 29 '19