运行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 <module>
    import tf
  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 "/opt/ros/melodic/lib/python2.7/dist-packages/tf2_ros/__init__.py", line 38, in <module>
    from tf2_py import *
  File "/opt/ros/melodic/lib/python2.7/dist-packages/tf2_py/__init__.py", line 38, in <module>
    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

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

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论
在你的错误信息中,ImportError: dynamic module does not define module export function (PyInit_cv_bridge_boost),这可能是由于ROS自带的cv_bridge只支持Python2而不是Python3导致的。为了解决这个问题,你需要编译一个适用于Python3的cv_bridge模块。 以下是解决方案: 1. 首先,确保你在系统的真实环境中操作,而不是在conda创建的虚拟环境中。打开一个新终端,并运行conda deactivate命令,确保退出所有虚拟环境。 2. 进入Python3环境并安装相关依赖包: ``` sudo apt-get install python-catkin-tools python3-dev python3-catkin-pkg-modules python3-numpy python3-yaml ros-melodic-cv-bridge ``` 注意,根据你使用的ROS版本可能会有略微不同的依赖包名称。 3. 创建一个工作空间用于存放待编译的cv_bridge文件: ``` mkdir -p catkin_ws_for_cvbridge/src ``` 4. 设置参数: ``` cd catkin_ws_for_cvbridge catkin config -DPYTHON_EXECUTABLE=/usr/bin/python3 -DPYTHON_INCLUDE_DIR=/usr/include/python3.6m -DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.6m.so ``` 注意,这里的参数根据你系统自带的Python版本进行设置,16.04使用Python3.5,18.04使用Python3.6。 5. 告诉catkin将构建的包安装到指定位置: ``` catkin config --install ``` 6. 在catkin_workspace工作空间中克隆cv_bridge: ``` git clone https://github.com/ros-perception/vision_opencv.git src/vision_opencv ``` 7. 查看适合的cv_bridge版本: ``` apt-cache show ros-melodic-cv-bridge | grep Version ``` 8. 编译cv_bridge: ``` catkin build cv_bridge ``` 如果一切顺利,应该能够成功编译cv_bridge模块。 9. 最后,确保你将编译后的cv_bridge包添加到ROS的环境变量中。 通过以上步骤,你应该能够解决ImportError: dynamic module does not define module export function (PyInit_cv_bridge_boost)的问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [在Python3环境中使用ROS的cv_bridge](https://download.csdn.net/download/weixin_38703794/14036198)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [【bug】ImportError: dynamic module does not define module export function (PyInit_cv_bridge_boost)](https://blog.csdn.net/qq_36497369/article/details/128853820)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Kane1440

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值