ImportError: No module named catkin_pkg.packages

Question:

I am trying to run:-
roslaunch turtlebot_gazebo turtlebot_world.launch

but I am getting following error

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 56, in <module>
    from .launch import ROSLaunchRunner
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/roslaunch/launch.py", line 55, in <module>
    from roslaunch.nodeprocess import create_master_process, create_node_process
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/roslaunch/nodeprocess.py", line 49, in <module>
    from roslaunch.node_args import create_local_process_args
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/roslaunch/node_args.py", line 53, in <module>
    import roslib.packages
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/roslib/__init__.py", line 54, in <module>
    import roslib.stacks
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/roslib/stacks.py", line 46, in <module>
    import roslib.packages
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/roslib/packages.py", line 49, in <module>
    from catkin.find_in_workspaces import find_in_workspaces as catkin_find
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/catkin/find_in_workspaces.py", line 36, in <module>


from catkin_pkg.packages import find_packages
ImportError: No module named catkin_pkg.packages
while processing /opt/ros/kinetic/share/turtlebot_gazebo/launch/includes/kobuki.launch.xml:
Invalid <param> tag: Cannot load command parameter [robot_description]: command [/opt/ros/kinetic/share/xacro/xacro.py '/opt/ros/kinetic/share/turtlebot_description/robots/kobuki_hexagons_asus_xtion_pro.urdf.xacro'] returned with code [1]. 

Answers:

This worked for me

pip install catkin_pkg

On Arch Linux: In my case, I installed from an AUR package python2-catkin_pkg which installed the library at /usr/lib/python2.7/site-packages. So just do a symlink from /opt/ros/kinetic/lib/python2.7/site-packages to /usr/lib/python2.7/site-packages/catkin_pkg. So do this when you’re in /usr/lib/python2.7/site-packages directory:

ln -s /usr/lib/python2.7/site-packages/catkin_pkg catkin_pkg
Answered By: amenji

Probably because your python version is too high as it was in my case. Try to use the system default python first.

Go back to /usr/bin/python3 and use that as the default.

Answered By: Yaolin Ge

For those who have conda installed, here is the solution:
https://github.com/colcon/colcon-ros/issues/118#issuecomment-1355078266

You need to install catkin_pkg into the environment. I’m using conda and I had to install catkin_pkg, empy, and lark:

 conda install -c conda-forge catkin_pkg empy lark
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.