Ask Your Question
0

ImportError: dynamic module does not define init function (init_tf2)

asked 2019-12-31 22:11:07 -0500

svdeepak99 gravatar image

Hello. I am trying to "import tf" in a python 2.7 terminal, but I am getting the following error. Please help me up, as I am unable to proceed further:

svdeepak99@Deepak-Strix:~/catkin_ws$ python
Python 2.7.17 (default, Nov  7 2019, 10:07:09) 
[GCC 7.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/ros/melodic/lib/python2.7/dist-packages/tf/__init__.py", line 30, in <module>
    from tf2_ros import TransformException as Exception, ConnectivityException, LookupException, ExtrapolationException
  File "/home/svdeepak99/catkin_ws/devel/lib/python3/dist-packages/tf2_ros/__init__.py", line 35, in <module>
    exec(__fh.read())
  File "<string>", line 38, in <module>
  File "/home/svdeepak99/catkin_ws/devel/lib/python3/dist-packages/tf2_py/__init__.py", line 35, in <module>
    exec(__fh.read())
  File "<string>", line 38, in <module>
ImportError: dynamic module does not define init function (init_tf2)
>>>

I am using ros melodic and Ubuntu 18.04 version. Thanks in advance.

edit retag flag offensive close merge delete

Comments

1

You seem to be mixing Python 2 and Python 3 (note python2.7/dist-packages/tf and python3/dist-packages/tf2_ros mentioned in the error).

You'll have to make sure not to do that.

gvdhoorn gravatar image gvdhoorn  ( 2020-01-01 05:56:22 -0500 )edit

Thanks for the reply. I tried uninstalling & reinstalling tf & tf2 packages using apt-get multiple number of times, but that doesn't solve my issue. Could you please suggest me how to solve this?

svdeepak99 gravatar image svdeepak99  ( 2020-01-01 10:39:47 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-01-02 13:20:53 -0500

tfoote gravatar image

We have worked hard to make sure that the code can be run in python 2 or python 3. But you must choose one and remain consistent. Mixing them will not work.

As @gvdhoorn mentioned you are mixing your environment with python2 and python3 instances. To resolve this make sure to consistently use the same python interpreter in any workspace. Note that for melodic the default python interpreter is python2.

If you used a different python interpreter to build or install a workspace you will want to completely clean the generated outputs and rebuild your workspace with the version of python you want.

edit flag offensive delete link more

Comments

Thank you so much. That solved my problem. I just took backup of the files in "src" folder, then deleted the catkin_ws folder, created a new catkin workspace, copied the backed up files into the new "src" folder and ran "catkin_make" command. The error is solved now.

svdeepak99 gravatar image svdeepak99  ( 2020-02-12 04:42:22 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2019-12-31 22:05:28 -0500

Seen: 2,877 times

Last updated: Jan 02 '20