ImportError: dynamic module does not define module export function (PyInit__tf2)
在运行命令 roslaunch turtle_tf turtle_tf_demo.launch 命令的时候发现出现错误,只出现了一只小海龟,后面有ImportError: dynamic module does not define module export function (PyInit__tf2)错误提示。
查阅了各种博客之后,发现是Python环境没有配置好。
可能是因为Python版本数太多的原因造成的。
首先确定安装了rospkg包和tf包,并且已经退出了conda base环境
$ conda deactivate
#如果想要关闭自启动base环境
$ conda config --set auto_activate_base false
$ pip3 install rospkg
$ sudo apt-get install ros-melodic-tf
如果出现上面的错误就查看tf包的位置
$ pip3 show tf
Name: tf
Version: 1.12.1
Summary: tf is a package that lets the user keep track of multiple coordinate
Home-page: None
Author: None
Author-email: None
License: None
Location: /opt/ros/melodic/lib/python2.7/dist-packages
Requires:
Required-by
可以看到tf包的位置在Python2.7的环境中
然后更改 .bashrc 文件:
$ gedit .bashrc
#在最后一行添加:
alias python=python2
然后确定Python可以导入tf包
$ python
Python 2.7.17 (default, Sep 30 2020, 13:38:04)
[GCC 7.5.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tf
再次运行roslaunch turtle_tf turtle_tf_demo.launch 会发现成功了,turtle2可以跟随turtle1运动了