ImportError: No module named rospkg (python3) <SOLVED>
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?
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.
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
sudo apt install python-is-python3
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