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

tf AttributeError: 'module' object has no attribute 'transformations'

asked 2014-05-27 06:46:00 -0500

updated 2014-05-27 06:49:28 -0500

I'm using roscopter package to get the imu data from my quadcopter.

It worked well but I got error when running it today.

rosrun roscopter imu_transform_publish.py

[ERROR] [WallTime: 1401208503.130663] bad callback: <function imu_callback at 0x18c9578>
Traceback (most recent call last):
File "/opt/ros/hydro/lib/python2.7/dist-packages/rospy/topics.py", line 682, in _invoke_callback
cb(msg)
File "/home/aqua/ros_catkin/src/roscopter/scripts/imu_transform_publish.py", line 75, in imu_callback
q = tf.transformations.quaternion_from_euler(roll,pitch,yaw)
AttributeError: 'module' object has no attribute 'transformations'

import tf

q = tf.transformations.quaternion_from_euler(roll,pitch,yaw)

According to the tf tutorial, tf.transformations.quaternion_from_euler(roll,pitch,yaw) should be correct, so I'm confused where the problem is.

also for the tf module, it locates in my catkin workspace:

Python 2.7.4 (default, Sep 26 2013, 03:20:26) 
[GCC 4.7.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tf
>>> print tf
<module 'tf' from '/home/aqua/ros_catkin/devel/lib/python2.7/dist-packages/tf/__init__.pyc'>
edit retag flag offensive close merge delete

Comments

Hi, i am new to ros and just met the same problem. Just download a new tf-file from github as you did. But what should i do afterwards? Would you please explain more about integrating this file into catkin_ws? I use catkin_make rather than rosbuild

Jian1994 gravatar image Jian1994  ( 2019-11-25 16:34:41 -0500 )edit

@Jian1994 just put it into your catkin workspace

lanyusea gravatar image lanyusea  ( 2019-11-25 20:34:59 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2014-05-27 08:11:58 -0500

tfoote gravatar image

updated 2014-05-27 08:12:32 -0500

I cannot reproduce this problem in source:

In [1]: import tf
In [2]: tf.transformations.quaternion_from_euler(1,2,3)
Out[2]: array([-0.71828702,  0.31062245,  0.44443511,  0.43595284])
In [3]: print(tf)
<module 'tf' from '/home/tfoote/work/geometry_experimental/devel/lib/python2.7/dist-packages/tf/__init__.pyc'>

Or from debian packages:

In [1]: import tf
In [2]: tf.transformations.quaternion_from_euler(1,2,3)
Out[2]: array([-0.71828702,  0.31062245,  0.44443511,  0.43595284])
In [3]: print(tf)
<module 'tf' from '/opt/ros/hydro/lib/python2.7/dist-packages/tf/__init__.pyc'>

I'd suggest that you make sure that your environment is clean and the referenced init script is pointing to a valid source directory.

edit flag offensive delete link more

Comments

I still failed... Could you help check what is inside folder `home/tfoote/work/geometry_experimental/devel/lib/python2.7/dist-packages/tf`? beside __init__.py __init__.pyc I found the `msg` and `srv` folders but both are empty.

lanyusea gravatar image lanyusea  ( 2014-05-27 08:20:49 -0500 )edit
1

thanks. I downloaded https://github.com/ros/geometry/tree/hydro-devel/tf to my catkinWorkspace and build it, it works.

lanyusea gravatar image lanyusea  ( 2014-05-27 08:38:54 -0500 )edit

That suggests that you have not fully built the package. The generated messages are required and your tf library is probably missing the compiled so files too making the import malfunction. Although you're using the python pieces, some of them depend on compiled and generated code from the build step.

tfoote gravatar image tfoote  ( 2014-05-27 08:38:54 -0500 )edit
0

answered 2023-05-12 13:37:16 -0500

I met the same problem because I made a stupid mistake which is I named the python file as tf.py so this program just import my python file as module. I know it's not the same problem as described above but I still just leave the comment hope maybe it helps someone.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-05-27 06:46:00 -0500

Seen: 5,287 times

Last updated: May 27 '14