在运行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使用需求。