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

ImportError: No module named rospkg (python3) <SOLVED>

asked 2016-10-19 00:51:22 -0500

DannyMB gravatar image

updated 2016-10-24 08:30:27 -0500

ngrennan gravatar image

Hi, I am using ROS Indigo in Raspbian Jessie on Raspberry pi 3, I am trying of read a compass (HC5883L) using library for read ports i2c (i2clibraries and quick2wire-python-api) but, when I run my file it given me this error:

Traceback (most recent call last):
  File "/home/pi/ros_catkin_ws/src/ceres_pkg/src/Brujula.py", line 5, in <module>
    import roslib; roslib.load_manifest('ceres_pkg')
  File "/home/pi/ros_catkin_ws/devel/lib/python2.7/dist-packages/roslib/__init__.py", line 35, in <module>
    exec(__fh.read())
  File "<string>", line 50, in <module>
  File "/home/pi/ros_catkin_ws/src/ros/roslib/src/roslib/launcher.py", line 42, in <module>
    import rospkg
ImportError: No module named 'rospkg'

this is my code:

#!/usr/bin/python3 #I use python3 because quick2wire only run with this.
import sys
sys.path.append("/home/pi/ros_catkin_ws/src/ceres_pkg/src/quick2wire-python-api")
import time
import roslib; roslib.load_manifest('ceres_pkg')
import rospy
import math
from geometry_msgs.msg import Point
from i2clibraries import i2c_hmc5883l

class Brujula(object):
    def __init__(self):
        self.pub_ = rospy.Publisher("/Brujula", Point, queue_size = 1)
        return
    def start(self):
        loop_rate = rospy.Rate(1)
        while not rospy.is_shutdown():
            hmc5883l = i2c_hmc5883l.i2c_hmc5883l(1)
            hmc5883l.setDeclination(9,54)
            hmc = float(hmc5883l.getHeadingString())
            pos_msg = Point(hmc)
            self.pub_.publish(pos_msg);
            loop_rate.sleep()
        return

if __name__ == '__main__':
    rospy.init_node('Brujula_py', log_level=rospy.INFO)
    rospy.loginfo("%s: starting Brujulagps node", rospy.get_name())
    brujula = Brujula()
    brujula.start()

My first step was read the compas, like this:

#!/usr/bin/python
import sys
import time
sys.path.append("/home/pi/ros_catkin_ws/src/ceres_pkg/src/quick2wire-python-api")
from i2clibraries import i2c_hmc5883l
while True:
    hmc5883l = i2c_hmc5883l.i2c_hmc5883l(1)
    hmc5883l.setDeclination(9,54)
    hmc = float(hmc5883l.getHeadingString())
    print(hmc)
    time.sleep(1)

But, when I convert to ROS code, this its broken.

Thanks for your time, and I hope that someone can help me.


Edit: I can solve, I install python3-rospkg:

sudo apt-get install python3-rospkg

But now, I have a new mistake:

ImportError: No module named 'catkin_pkg'

I tried to install

sudo apt-get install python3-catkin_pkg

But don't find any.

Any suggestions?

edit retag flag offensive close merge delete

Comments

have you sourced the ROS workspace? I.e., does echo $ROS_PACKAGE_PATH in the terminal you are trying to run this return anything? If yes, please edit your question with this output.

Also, I'm not quite sure how safe ROS is currently for python3.

mgruhler gravatar image mgruhler  ( 2016-10-19 01:29:37 -0500 )edit

Yes, I have my worksapace, and all the proyect there is, for to run the file I use:

pi@raspberry: ~/ros_catkin_ws/src/ceres_pkg/src $ rosrun ceres_pkg Brujula.py

DannyMB gravatar image DannyMB  ( 2016-10-19 01:48:45 -0500 )edit

sudo apt install python-is-python3

systembulangen gravatar image systembulangen  ( 2022-03-22 01:08:01 -0500 )edit

This is an issue because Ubuntu 20.04 has dropped python and python2, and now using python 3. Install the following lib to run ROS on Ubuntu 20.04: sudo apt install python-is-python3

systembulangen gravatar image systembulangen  ( 2022-03-22 01:08:18 -0500 )edit

3 Answers

Sort by ยป oldest newest most voted
1

answered 2016-10-19 11:40:22 -0500

ahendrix gravatar image

sudo apt-get install python3-catkin-pkg

edit flag offensive delete link more

Comments

Thanks @ahendrix ! that was the solution!

DannyMB gravatar image DannyMB  ( 2016-10-19 11:59:36 -0500 )edit
4

I'm running indigo on Ubuntu 14.04. Running this command causes apt to uninstall ROS for me.

csherstan gravatar image csherstan  ( 2017-01-23 12:23:56 -0500 )edit

I'd guess your problem is that python3-catkin-pkg conflicts with python-catkin-pkg, and much of ROS depends on that (python 2) version. You probably have to build ROS in a virtualenv from source using python3, instead. Good luck with that!

joq gravatar image joq  ( 2017-01-27 09:46:50 -0500 )edit
2

I had the same problem as you, csherstan. I solved this problem by installing the catkin_pkgs with the command:

sudo apt-get install python-catkin-pkg

And then I installed the python3-catkin-pkg-modules, with the command

sudo apt-get install python3-catkin-pkg-modules
Ari.Schneider gravatar image Ari.Schneider  ( 2017-06-18 16:15:32 -0500 )edit
11

answered 2018-07-23 05:37:03 -0500

updated 2018-07-24 03:13:27 -0500

This is what worked for me:

sudo apt-get install python3-catkin-pkg-modules
sudo apt-get install python3-rospkg-modules

I am using ROS Kinetic on Ubuntu 16.04 in a Jetson TX2.

edit flag offensive delete link more

Comments

1

I had to do this for Melodic on 18.04

billtheplatypus gravatar image billtheplatypus  ( 2018-07-26 16:15:42 -0500 )edit

In the future upgrading the Debian package of any of the ROS Python packages (catkin_pkg, rospkg, rosdistro, ros_buildfarm) will ensure that the -modules Debian package is updated too: see https://github.com/ros-infrastructure...

Dirk Thomas gravatar image Dirk Thomas  ( 2018-07-26 16:58:32 -0500 )edit

this should be the accepted answer

ticotico gravatar image ticotico  ( 2021-11-17 08:46:32 -0500 )edit
0

answered 2022-03-22 01:07:44 -0500

This is an issue because Ubuntu 20.04 has dropped python and python2, and now using python 3. Install the following lib to run ROS on Ubuntu 20.04: sudo apt install python-is-python3

edit flag offensive delete link more

Comments

Thanks,I solved it

Gomimaker gravatar image Gomimaker  ( 2023-04-15 07:02:49 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2016-10-19 00:51:22 -0500

Seen: 33,518 times

Last updated: Jul 24 '18