Ask Your Question
0

ImportError: dynamic module does not define module export function (PyInit__tf2)

asked 2019-06-19 01:52:50 -0600

joonhyup gravatar image

updated 2019-06-19 01:59:50 -0600

gvdhoorn gravatar image

When I tried to do tutorial of tf, I got an error as follw. And same error is occurred when I tried to do the tutorial of tf2.

How can I fix the problem? Thanks

Traceback (most recent call last):
  File "/home/bjh/catkin_ws/src/learning_tf2/nodes/static_turtle_tf2_broadcaster.py", line 8, in <module>
    import tf
  File "/home/bjh/catkin_ws/devel/lib/python2.7/dist-packages/tf/__init__.py", line 35, in <module>
    exec(__fh.read())
  File "<string>", line 30, in <module>
  File "/home/bjh/catkin_ws/devel/lib/python2.7/dist-packages/tf2_ros/__init__.py", line 35, in <module>
    exec(__fh.read())
  File "<string>", line 38, in <module>
  File "/home/bjh/catkin_ws/devel/lib/python2.7/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 module export function (PyInit__tf2)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
5

answered 2019-06-19 15:52:14 -0600

r7vme gravatar image

Issue is because tf2_ros was compiled for python2. Detailed discussion here.

To recompile for python3 (melodic):

Install some prerequisites to use Python3 with ROS.

sudo apt update
sudo apt install python3-catkin-pkg-modules python3-rospkg-modules python3-empy

Prepare catkin workspace

mkdir -p ~/catkin_ws/src; cd ~/catkin_ws
catkin_make
source devel/setup.bash
wstool init
wstool set -y src/geometry2 --git https://github.com/ros/geometry2 -v 0.6.5
wstool up
rosdep install --from-paths src --ignore-src -y -r

Finally compile for Python 3

catkin_make --cmake-args \
            -DCMAKE_BUILD_TYPE=Release \
            -DPYTHON_EXECUTABLE=/usr/bin/python3 \
            -DPYTHON_INCLUDE_DIR=/usr/include/python3.6m \
            -DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.6m.so

Do not forget to always source your workspace!

edit flag offensive delete link more

Comments

I am very appreciate for your help! It is done!

joonhyup gravatar imagejoonhyup ( 2019-06-20 18:15:30 -0600 )edit

Good to hear! @joonhyup can you please accept answer if it helped?

r7vme gravatar imager7vme ( 2019-06-20 21:18:42 -0600 )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

3 followers

Stats

Asked: 2019-06-19 01:52:50 -0600

Seen: 3,688 times

Last updated: Jun 19