import tf
删除提示异常的文件
$ cd /opt/ros/melodic/lib/python2.7/dist-packages/
$ sudo rm -r tf .tf tf2_ros .tf2_ros tf2_py .tf2_py
新建一个workspace,用来编译geometry
、geometry2
两个包。
$ mkdir -p test_env_ws/src
$ cd test_env_ws/src
$ export ROS_PYTHON_VERSION=3
$ sudo gedit /opt/ros/melodic/share/ros_environment/catkin_env_hook/1.ros_python_version.sh
$ catkin_init_workspace
$ git clone https://github.com/ros/geometry
$ git clone https://github.com/ros/geometry2
$ cd ..
$ catkin_make
编译时显示的python版本要是3.x.x
import tf
成功。