天天看點

except OSError, e: ^ SyntaxError: invalid syntax(baxter SDK編譯過程中出現的問題)

baxter SDK  隻能在python2.7的環境下通過編譯 ---文法格式問題

報錯片段:

Traceback (most recent call last):
  File "/home/yan/baxter_ws/src/baxter_interface/cfg/HeadActionServer.cfg", line 35, in <module>
    from baxter_interface import settings
  File "/home/yan/baxter_ws/devel/lib/python2.7/dist-packages/baxter_interface/__init__.py", line 35, in <module>
    exec(__fh.read())
  File "<string>", line 35, in <module>
  File "/home/yan/baxter_ws/src/baxter_interface/src/baxter_interface/robot_enable.py", line 167
    except OSError, e:
                  ^
SyntaxError: invalid syntax
baxter_interface/CMakeFiles/baxter_interface_gencfg.dir/build.make:143: recipe for target '/home/yan/baxter_ws/devel/include/baxter_interface/HeadActionServerConfig.h' failed
make[2]: *** [/home/yan/baxter_ws/devel/include/baxter_interface/HeadActionServerConfig.h] Error 1
CMakeFiles/Makefile2:3427: recipe for target 'baxter_interface/CMakeFiles/baxter_interface_gencfg.dir/all' failed
make[1]: *** [baxter_interface/CMakeFiles/baxter_interface_gencfg.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j8 -l8" failed
           

解決辦法:

使用conda建立新的虛拟環境 使用python2.7版本

conda create -n py27 python=2.7
conda activate py27
           

重新執行

catkin_make
           

如果又發現報錯:

Traceback (most recent call last):
  File "/home/yan/baxter_ws/src/baxter_interface/cfg/HeadActionServer.cfg", line 30, in <module>
    from dynamic_reconfigure.parameter_generator_catkin import (
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/dynamic_reconfigure/__init__.py", line 38, in <module>
    import roslib
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/roslib/__init__.py", line 50, in <module>
    from roslib.launcher import load_manifest
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/roslib/launcher.py", line 42, in <module>
    import rospkg
ImportError: No module named rospkg
baxter_interface/CMakeFiles/baxter_interface_gencfg.dir/build.make:143: recipe for target '/home/yan/baxter_ws/devel/include/baxter_interface/HeadActionServerConfig.h' failed
make[2]: *** [/home/yan/baxter_ws/devel/include/baxter_interface/HeadActionServerConfig.h] Error 1
CMakeFiles/Makefile2:3427: recipe for target 'baxter_interface/CMakeFiles/baxter_interface_gencfg.dir/all' failed
make[1]: *** [baxter_interface/CMakeFiles/baxter_interface_gencfg.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j8 -l8" failed
           

這次是因為安裝了anaconda

首先嘗試

apt-cache search rospkg
sudo apt-get install python-rospkg
           

上面的方法并沒有效果,借用别人的方法:

conda install setuptools
 pip install -U rosdep rosinstall_generator wstool rosinstall six vcstools
           

成功解決