【问题标题】:Import a local library in Choregraphe在 Choregraphe 中导入本地库
【发布时间】:2018-03-17 17:24:13
【问题描述】:

我正在用 choregraphe 编写一个块的代码,我需要 numpy 和枕头库中的一些函数。我使用 pip 在行为的同一文件夹中安装了枕头和 numpy。在 Choregraphe 里面我试过的块代码:

from sys import path
path.append(ALFrameManager.getBehaviorPath(self.behaviorId))
from PIL import Image
from scipy import array, inf
from scipy.sparse.csgraph import shortest_path, csgraph_from_dense

我得到这个错误:

ImportError: cannot import name _imaging

如果我评论该行

from PIL import Image

我收到此错误:

ImportError: 
Importing the multiarray numpy extension module failed.  Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control).  Otherwise reinstall numpy.

Original error was: cannot import name multiarray

我尝试重新安装这两个库,但没有任何变化。我哪里错了?在同一个文件夹里还有一个我写的类但是导入没有问题,我不明白为什么

【问题讨论】:

    标签: python scipy python-imaging-library choregraphe


    【解决方案1】:

    您是在机器人上运行此程序(哪个?哪个操作系统版本?),还是在您的计算机上本地运行?

    如果它在机器人上,很可能包中包含的库的 .so 文件(和其他二进制文件)未针对正确的架构进行编译。

    一些可能性:

    • 使用已经在机器人上的 numpy(不会帮助你使用 scipy,我不认为它在机器人上,我可能错了)(如果 PIL 也已经在机器人,我记得好像见过它,但没有方便的机器人检查)
    • 在 NAOqi 2.5 中,使用机器人上已经存在的 pip;但首先你需要升级它:
    pip install --user --upgrade pip
    

    然后

    /home/nao/.local/bin/pip install --user scipy (or whatever other package you need)
    

    然后,您不需要将这些文件打包到您的 choregraphe 包中(但您必须在要安装它的所有机器人上执行相同的过程,这可能适合您的用例,也可能不适合您的用例。

    【讨论】:

    • 我没有机器人,所以我只是想在 Choreographe 的模拟器上运行它
    • 在这种情况下,问题是 Choregraphe 使用的 python 评估器是嵌入的,而不是使用计算机中的 python 二进制文件和库。一个非常讨厌的方法是使用一些 Popen 风格的命令从 python 代码中调用计算机 python。不过是不是很丑啊……
    • 在一个编排的虚拟机器人上,ALFrameManager.getBehaviorPath 可能帮不上什么忙;但在这种情况下,您可以尝试将计算机上的实际库路径附加到 sys.path。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-15
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    • 2014-05-15
    • 2013-05-21
    相关资源
    最近更新 更多