【Debug记录】Ros报错:解决Gazebo或Ros相关组件运行命令报错:dynamic module does not define module export function的方法

【Debug记录】Ros报错:解决Gazebo或Ros相关组件运行命令报错:dynamic module does not define module export function的方法

问题描述:

在运行gazebo或者roslaunch时会报错:dynamic module does not define module export function导致命令无法执行。
如下图是在运行以下命令调用tf2功能包时的报错:

roslaunch turtle_tf turtle_tf_demo.launch 

在这里插入图片描述

报错日志:

Traceback (most recent call last):
  File "/opt/ros/melodic/lib/turtle_tf/turtle_tf_broadcaster.py", line 37, 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)
Traceback (most recent call last):
  File "/opt/ros/melodic/lib/turtle_tf/turtle_tf_broadcaster.py", line 37, 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)
Traceback (most recent call last):
  File "/opt/ros/melodic/lib/turtle_tf/turtle_tf_listener.py", line 37, 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)
[turtle1_tf_broadcaster-4] process has died [pid 10323, exit code 1, cmd /opt/ros/melodic/lib/turtle_tf/turtle_tf_broadcaster.py __name:=turtle1_tf_broadcaster __log:=/home/chen/.ros/log/24d0e0b8-d140-11ea-b872-74c63b364989/turtle1_tf_broadcaster-4.log].
log file: /home/chen/.ros/log/24d0e0b8-d140-11ea-b872-74c63b364989/turtle1_tf_broadcaster-4*.log
[turtle2_tf_broadcaster-5] process has died [pid 10329, exit code 1, cmd /opt/ros/melodic/lib/turtle_tf/turtle_tf_broadcaster.py __name:=turtle2_tf_broadcaster __log:=/home/chen/.ros/log/24d0e0b8-d140-11ea-b872-74c63b364989/turtle2_tf_broadcaster-5.log].
log file: /home/chen/.ros/log/24d0e0b8-d140-11ea-b872-74c63b364989/turtle2_tf_broadcaster-5*.log
[turtle_pointer-6] process has died [pid 10331, exit code 1, cmd /opt/ros/melodic/lib/turtle_tf/turtle_tf_listener.py __name:=turtle_pointer __log:=/home/chen/.ros/log/24d0e0b8-d140-11ea-b872-74c63b364989/turtle_pointer-6.log].
log file: /home/chen/.ros/log/24d0e0b8-d140-11ea-b872-74c63b364989/turtle_pointer-6*.log

问题原因:

出现这种问题一般是由于Ros目前只支持Python2,一些主要的功能包如tf2等都是在Python2的环境下运行的,在Python2中导入相关包不会出现问题,但在Python3中会出错。而目前大部分用户Ubuntu习惯配置和优先使用Python3,所以会导致这类问题出现。

解决方法:

打开bashrc,修改系统环境变量配置文件,找到当时定位Anaconda的环境变量:

export PATH="/home/chen/anaconda3/bin:$PATH"

修改为:

export PYTHON_PATH="/home/chen/anaconda3/bin"

修改后:
在这里插入图片描述

至此问题解决,并且不会影响日常其他程序的Python3使用需求。

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值