问题:这两天安装cartographer,总是遇到错误:Unrecognized syntax identifier "proto3". This parser only recognizes "proto2",后来安装proto2和proto3都试过,但是还是报同样错,最后删除cartographer重新安装又出现:ImportError: No module named cmd.build等错误。(使用环境ubuntu16.04、ROS Kinetic、python2.7)
问题分析:由于ros支持python2.7,而syntax是在python3.5环境下安装的,执行语句catkin_make_isolated --install --use-ninja总是报错:Unrecognized syntax identifier "proto3". This parser only recognizes "proto2"
解决方案:执行上面语句之前先用update-alternatives --config python切换到python3.5环境:
csl@csl-Lenovo-M50-70:~/cartographer_ws$ sudo update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/python3.5 2 auto mode
* 1 /usr/bin/python2.7 1 manual mode
2 /usr/bin/python3.5 2 manual mode
Press <enter> to keep the current choice[*], or type selection number: 0
update-alternatives: using /usr/bin/python3.5 to provide /usr/bin/python (python) in auto mode
csl@csl-Lenovo-M50-70:~/cartographer_ws$ catkin_make_isolated --install --use-ninja
Base path: /home/csl/cartographer_ws
在python3.5环境下再执行catkin_make_isolated --install --use-ninja,编译通过!!!!
安装完cartographer后,为了支持ROS编译环境可以同同样的方法切回python2.7环境
注意:上面问题是在python2环境下运行的产生,安装的cartographer为至今最新版。每次使用catkin_make_isolated --install --use-ninja编译cartographer时都需要切换到python3环境下,而编译运行ROS程序时需切换到python2环境!!!
由于cartographer对python3支持比较好,建议ROS使用python3环境,ROS中使用python3遇到的一些问题见下链接:
https://blog.csdn.net/bm5201314tcdj/article/details/98095411
catographer安装参考:https://blog.csdn.net/qq_38649880/article/details/87719394
python版本切换参考:https://blog.csdn.net/u013894834/article/details/75305752