Robotics StackExchange | Archived questions

ImportError: No module named tf

I am writing a node that involves calculating the distance from the PR2's left wrist to a point in space, and publishing that distance. The point is in the base frame, so to make calculations easier I'm attempting to change the frame of the point. However, when I run it, nothing is published (when I use rostopic echo, it indicates that the parameter is not being published. Essentially it doesn't know that it exists). I tried using rosrun on the file and it errors saying

ImportError: No module named tf

Here's what the beginning of my code looks like

#!/usr/bin/env python

# This publisher will calculated the distance of an object
# from PR2
import roslib
roslib.load_manifest('PR2_assignment0')
import rospy
import sys
from std_msgs.msg import String
import tf

from std_msgs.msg import Float64
from geometry_msgs.msg import PointStamped

I've made many modifications but it still does not seem to work (I've checked threads with similar problems but their solutions aren't working). Other files with a similar format work, but mine doesn't...

I haven't tried the code without the tf frame, so I'll try that out for now and see if it sheds light on some things.

Any suggestions?

Asked by kgnkwmr on 2015-03-13 16:27:32 UTC

Comments

Answers

From your description, it sounds like your Python script is being called from a workspace without your ROS Python path set properly. Make sure you have built your catkin workspace with catkin_make and then source your devel/setup.bash to set your environment. You can verify the environment is then set with env | grep PYTHON

foo@bar:~/ros_ws$ catkin_make
foo@bar:~/ros_ws$ source devel/setup.bash 
foo@bar:~/ros_ws$ env | grep PYTHON
PYTHONPATH=/home/foo/ros_ws/devel/lib/python2.7/dist-packages:/opt/ros/indigo/lib/python2.7/dist-packages:

Just a sidenote, if you are using a catkin workspace, you won't need import roslib and roslib.load_manifest('PR2_assignment0'). See the answer for the question What does roslibload_manifest do? for a more detailed explanation.

Asked by imcmahon on 2015-03-16 13:01:30 UTC

Comments

Try installing tf package using sudo apt-get install ros-<ros-distro>-tf.

Asked by Anubhav Singh on 2019-08-14 16:52:12 UTC

Comments