ubuntu 16.04 ros kinetic Moveit Python: ImportError: cannot import name structs

在使用moveit python binding的时候一直遇到如下问题:

Traceback (most recent call last):
  File "./moveit_plan.py", line 6, in <module>
    import moveit_commander
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/moveit_commander/__init__.py", line 3, in <module>
    from planning_scene_interface import *
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/moveit_commander/planning_scene_interface.py", line 48, in <module>
    import pyassimp
  File "/usr/lib/python2.7/dist-packages/pyassimp/__init__.py", line 1, in <module>
    from .core import *
  File "/usr/lib/python2.7/dist-packages/pyassimp/core.py", line 23, in <module>
    from . import structs
ImportError: cannot import name structs

该问题已经确认是pyassimp的bug,see link: https://github.com/ros-planning/moveit/issues/86

重新安装pyassimp解决该问题(如果pip安装出现问题,见下文pip的升级):

sudo pip uninstall pyassimp
and then,
sudo pip install pyassimp ,

如果安装完 pyassimp 后出现:

python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyassimp
Traceback (most recent call last):
  File "", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/pyassimp/__init__.py", line 1, in <module>
    from .core import *
  File "/usr/lib/python2.7/dist-packages/pyassimp/core.py", line 29, in <module>
    class AssimpLib(object):
  File "/usr/lib/python2.7/dist-packages/pyassimp/core.py", line 33, in AssimpLib
    load, load_mem, release, dll = helper.search_library()
ValueError: need more than 3 values to unpack
>>> 

则需要修改 /usr/lib/python2.7/dist-packages/pyassimp/core.py 一行代码:

将
load, load_mem, release, dll = helper.search_library()
修改成
load_mem, release, dll = helper.search_library()

在解决该问题的过程中,还遇到了pip升级的问题:

guowei@guowei-desktop:~$ pip install --upgrade pip
Collecting pip
  Using cached pip-9.0.1-py2.py3-none-any.whl
Installing collected packages: pip
  Found existing installation: pip 8.1.1
    Not uninstalling pip at /usr/lib/python2.7/dist-packages, outside environment /usr
Successfully installed pip-8.1.1
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

可能原因是我安装pip的时候是通过命令 sudo apt-get install python-pip 安装的,而不是通过get-pip.py安装的。然后apt系统阻止了升级操作。
解决方法是卸载 python-pip sudo apt-get remove python-pip 然后再通过get-pip.py重新安装pip:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py

重新安装pip后,系统可能找不到新安装的pip:

$ pip
-bash: /home/guowei/.local/bin/pip: No such file or directory

遇到这种情况,执行如下命令刷新cache解决:

hash -r

你可能感兴趣的:(issue,ros)