admin管理员组

文章数量:1558098

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

亲测有用!

主要参考:
这里

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

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

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

照着上面一字不差的运行完。
然后就会在目录~/catkin_ws/src/geometry2文件夹下生成你需要的包tf2_ros。后面就只需要把py文件中用到import tf2_ros的地方换成新的路径。
下面是其中一种解决方法:

import sys
sys.path.append("/home/lh/catkin_ws/src")
from geometry2 import tf2_ros

最后一行会报红,但不影响,可以忽略。

本文标签: ModuledynamicImportErrordefinefunction