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

TF2 Error: AttributeError: 'module' object has no attribute 'Buffer'

asked 2018-10-28 01:16:53 -0600

Kolohe113 gravatar image

updated 2018-10-29 15:22:46 -0600

Hello! I encountered an error when I tried to rosrun tf2_tools view_frames.py. I got the error:

[INFO] [1540707214.255858]: Listening to tf data during 5 seconds...
Traceback (most recent call last):
  File "/opt/ros/kinetic/lib/tf2_tools/view_frames.py", line 81, in <module>
    main()
  File "/opt/ros/kinetic/lib/tf2_tools/view_frames.py", line 44, in main
    buffer = tf2_ros.Buffer()
AttributeError: 'module' object has no attribute 'Buffer'

Did anyone encounter this problem before?

Edit: In a terminal, if I type which python: output: /usr/bin/python

$ python
Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tf2_ros
>>> from tf2_ros import Buffer
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name Buffer
>>>

Edit2:

~$ dpkg -l | grep tf2
ii  ros-ardent-ros-base                               0.4.0-1xenial-20180720-153419-0800                              amd64        A package which extends 'ros_core' and includes other basic functionalities like tf2 and urdf.
ii  ros-ardent-tf2                                    0.8.0-0xenial-20180208-143331-0800                              amd64        tf2 is the second generation of the transform library, which lets the user keep track of multiple coordinate frames over time.
ii  ros-ardent-tf2-eigen                              0.8.0-0xenial-20180208-144727-0800                              amd64        tf2_eigen
ii  ros-ardent-tf2-geometry-msgs                      0.8.0-0xenial-20180208-144706-0800                              amd64        tf2_geometry_msgs
ii  ros-ardent-tf2-msgs                               0.8.0-0xenial-20180208-143840-0800                              amd64        tf2_msgs
ii  ros-ardent-tf2-ros                                0.8.0-0xenial-20180208-144018-0800                              amd64        This package contains the ROS bindings for the tf2 library, for both Python and C++.
ii  ros-kinetic-tf2                                   0.5.18-0xenial-20180824-102527-0800                             amd64        tf2 is the second generation of the transform library, which lets the user keep track of multiple coordinate frames over time.
ii  ros-kinetic-tf2-bullet                            0.5.18-0xenial-20180824-124622-0800                             amd64        tf2_bullet
ii  ros-kinetic-tf2-eigen                             0.5.18-0xenial-20180824-124619-0800                             amd64        tf2_eigen
ii  ros-kinetic-tf2-geometry-msgs                     0.5.18-0xenial-20180824-132241-0800                             amd64        tf2_geometry_msgs
ii  ros-kinetic-tf2-kdl                               0.5.18-0xenial-20180824-132631-0800                             amd64        KDL binding for tf2
ii  ros-kinetic-tf2-msgs                              0.5.18-0xenial-20180824-101445-0800                             amd64        tf2_msgs
ii  ros-kinetic-tf2-py                                0.5.18-0xenial-20180824-123846-0800                             amd64        The tf2_py package
ii  ros-kinetic-tf2-ros                               0.5.18-0xenial-20180824-125648-0800                             amd64        This package contains the ROS bindings for the tf2 library, for both Python and C++.
ii  ros-kinetic-tf2-sensor-msgs                       0.5.18-0xenial-20180824-132057-0800                             amd64        Small lib to transform sensor_msgs with tf.
ii  ros-kinetic-tf2-tools                             0.5.18-0xenial-20180824-132425-0800                             amd64        tf2_tools
ii  ros-kinetic-turtle-tf2                            0.2.2-0xenial-20180824-132015-0800                              amd64        turtle_tf2 demonstrates how to write a tf2 broadcaster and listener with the turtlesim.

Edit 3 : If I run source /opt/ros/kinetic/setup.bash, I got a different error:

/opt/ros/kinetic$ rosrun tf2_tools view_frames.py 
[INFO] [1540844394.031532]: Listening to tf data during 5 seconds...
[INFO] [1540844399.056461]: Generating graph in frames.pdf file...
Traceback (most recent call last):
  File "/opt/ros/kinetic/lib/tf2_tools/view_frames.py", line 81, in <module>
    main()
  File "/opt/ros/kinetic/lib/tf2_tools/view_frames.py", line 52, in main
    with open('frames.gv', 'w') as f:
IOError: [Errno 13] Permission denied: 'frames.gv'
edit retag flag offensive close merge delete

Comments

Did anyone encounter this problem before?

no, and this is a rather strange error, as all of this should have been installed for you.

So:

  1. how did you install ROS?
  2. what OS is this?
  3. do you have Anaconda or another alternative Python intepreter installed?
gvdhoorn gravatar image gvdhoorn  ( 2018-10-28 04:57:46 -0600 )edit

1) I installed ROS by sudo apt-get install ros-kinetic-desktop-full 2) The OS is Ubuntu 16.04 3) I have not install any python interpreter or Anaconda, at least not that I know of. But my python version is 2.7.12

Kolohe113 gravatar image Kolohe113  ( 2018-10-28 21:32:40 -0600 )edit

What is the output of which python?

And what is the output of:

 $ python
 >>> import tf2_ros
 >>> from tf2_ros import Buffer

Please copy-paste the output into your original question. Use the edit button/link for that.

gvdhoorn gravatar image gvdhoorn  ( 2018-10-29 03:04:46 -0600 )edit

That is rather strange.

What is the output of dpkg -l | grep tf2?

gvdhoorn gravatar image gvdhoorn  ( 2018-10-29 03:25:52 -0600 )edit

Let's take a step back: are you still (trying to) use the TF2 package in your workspace, as in #q306956?

Can you please do the following and then test if things work. In a new terminal:

source /opt/ros/kinetic/setup.bash
python
from tf2_ros import Buffer
gvdhoorn gravatar image gvdhoorn  ( 2018-10-29 03:32:35 -0600 )edit

Similar to #q306956: do things work when you don't use your workspace?

gvdhoorn gravatar image gvdhoorn  ( 2018-10-29 04:40:25 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-10-30 03:02:01 -0600

gvdhoorn gravatar image

Edit 3 : If I run source /opt/ros/kinetic/setup.bash, I got a different error:

/opt/ros/kinetic$ rosrun tf2_tools view_frames.py 
[INFO] [1540844394.031532]: Listening to tf data during 5 seconds...
[INFO] [1540844399.056461]: Generating graph in frames.pdf file...
Traceback (most recent call last):
  File "/opt/ros/kinetic/lib/tf2_tools/view_frames.py", line 81, in <module>
    main()
  File "/opt/ros/kinetic/lib/tf2_tools/view_frames.py", line 52, in main
    with open('frames.gv', 'w') as f:
IOError: [Errno 13] Permission denied: 'frames.gv'

This just means that the current working directory (ie: the directory currently active) is one where your user doesn't have write permissions.

But it would seem the initial issue (not being able to properly use the tf2_ros Python module) is fixed with this.

My best guess is that you did not correctly clone and / or build the tf2 packages in your workspace which made view_frames.py fail.

Using the released binary packages makes everything work (that is why I asked you to source (ie: activate) the normal /opt/ros/kinetic/setup.bash file.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-10-28 01:16:53 -0600

Seen: 2,294 times

Last updated: Oct 30 '18