运行handeye-calib手眼标定:ImportError: dynamic module does not define module export function (PyInit__tf2)

一、问题描述

在运行 鱼香ROS手眼标定handeye-calib功能包的时候,出现了下列报错

wheeltec-client@ubuntu:~/Desktop/handeye-calib$ roslaunch handeye-calib online_hand_to_eye_calib.launch 
... logging to /home/wheeltec-client/.ros/log/70b5941e-4d26-11ee-9f7b-000c29bc7a6b/roslaunch-ubuntu-34491.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://192.168.0.100:44971/

SUMMARY
========

PARAMETERS
 * /online_hand_to_eye_calib/arm_pose_topic: /arm_pose
 * /online_hand_to_eye_calib/camera_pose_topic: /aruco_single/pose
 * /rosdistro: melodic
 * /rosversion: 1.14.13
 * /tf_to_pose/arm_pose_topic: /arm_pose
 * /tf_to_pose/base_link: /base_link
 * /tf_to_pose/end_link: /link5

NODES
  /
    online_hand_to_eye_calib (handeye-calib/online_hand_to_eye_calib.py)
    tf_to_pose (handeye-calib/tf_to_pose.py)

ROS_MASTER_URI=http://192.168.0.100:11311

process[online_hand_to_eye_calib-1]: started with pid [34506]
process[tf_to_pose-2]: started with pid [34507]
Traceback (most recent call last):
  File "/home/wheeltec-client/Desktop/handeye-calib/src/handeye-calib/src/handeye/tf_to_pose.py", line 9, in 
    import tf
  File "/opt/ros/melodic/lib/python2.7/dist-packages/tf/__init__.py", line 30, in 
    from tf2_ros import TransformException as Exception, ConnectivityException, LookupException, ExtrapolationException
  File "/opt/ros/melodic/lib/python2.7/dist-packages/tf2_ros/__init__.py", line 38, in 
    from tf2_py import *
  File "/opt/ros/melodic/lib/python2.7/dist-packages/tf2_py/__init__.py", line 38, in 
    from ._tf2 import *
ImportError: dynamic module does not define module export function (PyInit__tf2)
======================================================
          欢迎使用手眼标定程序,我是小鱼   
        学习机器人一定要关注公众号鱼香ROS      
         回复手眼标定可获得算法推导及实现      
------------------------------------------------------
            本程序中相关坐标系定义解析                 
   base_link:机械臂基坐标系(一般在固定在机器人底座)         
   end_link :机械臂末端坐标系(可在launch中配置)         
   camera   :相机坐标系         
   marker   :标定版所在坐标系         
======================================================
[INFO] [1694053849.133065]: 手眼标定需要两个位置和姿态,一个是机械臂末端的位姿,将从话题/arm_pose中获取 ,另一个相机中标定版的位置姿态将从话题/aruco_single/pose获取,所以请确保两个话题有数据
[tf_to_pose-2] process has died [pid 34507, exit code 1, cmd /home/wheeltec-client/Desktop/handeye-calib/src/handeye-calib/src/handeye/tf_to_pose.py __name:=tf_to_pose __log:=/home/wheeltec-client/.ros/log/70b5941e-4d26-11ee-9f7b-000c29bc7a6b/tf_to_pose-2.log].
log file: /home/wheeltec-client/.ros/log/70b5941e-4d26-11ee-9f7b-000c29bc7a6b/tf_to_pose-2*.log
[INFO] [1694053850.136647]: 等待机械臂位置和姿态话题到位 ...
^C[online_hand_to_eye_calib-1] killing on exit
[INFO] [1694053859.546004]: 等待机械臂位置和姿态话题到位 ...
shutting down processing monitor...
... shutting down processing monitor complete
done
wheeltec-client@ubuntu:~/Desktop/handeye-calib$ 

列下重点!

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

笔者尝试了很多方式,用virtualenv虚拟环境安装python3发现也报错,尝试修改python3文件适配2.7,只会越陷越深很多地方都有问题。最后在Ros answer上面找到了一个解决方案非常管用!

二、解决方法

问题是因为 tf2_ros 是为 python2 编译的。

为了重新编译 python3,需要以下操作以将 Python3 与 ROS 结合使用。

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

准备工作空间(这里我已经有工作空间了,就不创建了,直接在目录下运行即可)

sudo apt-get install python-wstool
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

最后编译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

搞定!可以愉快的进行手眼标定辣!

运行handeye-calib手眼标定:ImportError: dynamic module does not define module export function (PyInit__tf2)_第1张图片

你可能感兴趣的:(ROS学习日志,ROS机械臂,机器人,嵌入式硬件,ubuntu,linux,人工智能)