- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我一直在研究 project使用 libpython2.7.so 将 Python 解释器作为 MEX 文件嵌入到 MATLAB 中,但是每当我尝试导入作为扩展模块实现的 Python 模块时都会遇到问题。例如,尝试导入 itertools
会导致以下错误:
>> py_import itertools
ImportError: /usr/lib64/python2.7/lib-dynload/itertoolsmodule.so: undefined symbol: PyTuple_Type
??? Error using ==> pymex_fns
Python exception inside py_import.
Error in ==> py_import at 24
py_obj = pymex_fns(py_function_t.IMPORT, name);
无论我是否在调用 Py_Initialize()
之前清除 LD_LIBRARY_PATH
以及调用 ldd
(对于 itertools.so
,在本例中)从 MATLAB 内部不会导致任何 (not found)
消息。下面,我粘贴了在 LD_DEBUG=libs
设置下运行 MATLAB 的结果,首先是在 MATLAB 启动时设置了 LD_LIBRARY_PATH
,然后在运行 setenv('LD_LIBRARY_PATH ', '')
在尝试导入之前。
如何解决这个问题,并允许动态加载扩展模块?
使用 MATLAB 默认 LD_LIBRARY_PATH
:
>> py_import itertools
3018: find library=libpython2.7.so.1.0 [0]; searching
3018: search path=/usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64:/usr/local/MATLAB/R2011a/bin/glnxa64:/usr/local/MATLAB/R2011a/bin/glnxa64/../../sys/os/glnxa64 (RPATH from file /usr/local/MATLAB/R2011a/bin/glnxa64/MATLAB)
3018: trying file=/usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libpython2.7.so.1.0
3018: trying file=/usr/local/MATLAB/R2011a/bin/glnxa64/libpython2.7.so.1.0
3018: trying file=/usr/local/MATLAB/R2011a/bin/glnxa64/../../sys/os/glnxa64/libpython2.7.so.1.0
3018: search path=/usr/local/MATLAB/R2011a/sys/os/glnxa64 (LD_LIBRARY_PATH)
3018: trying file=/usr/local/MATLAB/R2011a/sys/os/glnxa64/libpython2.7.so.1.0
3018: search path=/usr/local/MATLAB/R2011a/bin/glnxa64 (RPATH from file /usr/local/MATLAB/R2011a/bin/glnxa64/MATLAB)
3018: trying file=/usr/local/MATLAB/R2011a/bin/glnxa64/libpython2.7.so.1.0
3018: search path=/usr/local/MATLAB/R2011a/extern/lib/glnxa64:/usr/local/MATLAB/R2011a/runtime/glnxa64:/usr/local/MATLAB/R2011a/sys/java/jre/glnxa64/jre/lib/amd64/native_threads:/usr/local/MATLAB/R2011a/sys/java/jre/glnxa64/jre/lib/amd64/server:/usr/local/MATLAB/R2011a/sys/java/jre/glnxa64/jre/lib/amd64 (LD_LIBRARY_PATH)
3018: trying file=/usr/local/MATLAB/R2011a/extern/lib/glnxa64/libpython2.7.so.1.0
3018: trying file=/usr/local/MATLAB/R2011a/runtime/glnxa64/libpython2.7.so.1.0
3018: trying file=/usr/local/MATLAB/R2011a/sys/java/jre/glnxa64/jre/lib/amd64/native_threads/libpython2.7.so.1.0
3018: trying file=/usr/local/MATLAB/R2011a/sys/java/jre/glnxa64/jre/lib/amd64/server/libpython2.7.so.1.0
3018: trying file=/usr/local/MATLAB/R2011a/sys/java/jre/glnxa64/jre/lib/amd64/libpython2.7.so.1.0
3018: search cache=/etc/ld.so.cache
3018: trying file=/lib64/libpython2.7.so.1.0
3018:
3018: find library=libutil.so.1 [0]; searching
3018: search path=/usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64:/usr/local/MATLAB/R2011a/bin/glnxa64:/usr/local/MATLAB/R2011a/bin/glnxa64/../../sys/os/glnxa64 (RPATH from file /usr/local/MATLAB/R2011a/bin/glnxa64/MATLAB)
3018: trying file=/usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libutil.so.1
3018: trying file=/usr/local/MATLAB/R2011a/bin/glnxa64/libutil.so.1
3018: trying file=/usr/local/MATLAB/R2011a/bin/glnxa64/../../sys/os/glnxa64/libutil.so.1
3018: search path=/usr/local/MATLAB/R2011a/sys/os/glnxa64 (LD_LIBRARY_PATH)
3018: trying file=/usr/local/MATLAB/R2011a/sys/os/glnxa64/libutil.so.1
3018: search path=/usr/local/MATLAB/R2011a/bin/glnxa64 (RPATH from file /usr/local/MATLAB/R2011a/bin/glnxa64/MATLAB)
3018: trying file=/usr/local/MATLAB/R2011a/bin/glnxa64/libutil.so.1
3018: search path=/usr/local/MATLAB/R2011a/extern/lib/glnxa64:/usr/local/MATLAB/R2011a/runtime/glnxa64:/usr/local/MATLAB/R2011a/sys/java/jre/glnxa64/jre/lib/amd64/native_threads:/usr/local/MATLAB/R2011a/sys/java/jre/glnxa64/jre/lib/amd64/server:/usr/local/MATLAB/R2011a/sys/java/jre/glnxa64/jre/lib/amd64 (LD_LIBRARY_PATH)
3018: trying file=/usr/local/MATLAB/R2011a/extern/lib/glnxa64/libutil.so.1
3018: trying file=/usr/local/MATLAB/R2011a/runtime/glnxa64/libutil.so.1
3018: trying file=/usr/local/MATLAB/R2011a/sys/java/jre/glnxa64/jre/lib/amd64/native_threads/libutil.so.1
3018: trying file=/usr/local/MATLAB/R2011a/sys/java/jre/glnxa64/jre/lib/amd64/server/libutil.so.1
3018: trying file=/usr/local/MATLAB/R2011a/sys/java/jre/glnxa64/jre/lib/amd64/libutil.so.1
3018: search cache=/etc/ld.so.cache
3018: trying file=/lib64/libutil.so.1
3018:
3018:
3018: calling init: /lib64/libutil.so.1
3018:
3018:
3018: calling init: /lib64/libpython2.7.so.1.0
3018:
3018:
3018: calling init: /home/cgranade/academics/software-projects/pymex-embed/src/pymex_fns.mexa64
3018:
3018: /home/cgranade/academics/software-projects/pymex-embed/src/pymex_fns.mexa64: error: symbol lookup error: undefined symbol: mexLibrary (fatal)
3018: /usr/lib64/python2.7/lib-dynload/itertoolsmodule.so: error: symbol lookup error: undefined symbol: PyTuple_Type (fatal)
??? Error using ==> pymex_fns
Python exception inside py_import.
Error in ==> py_import at 24
py_obj = pymex_fns(py_function_t.IMPORT, name);
清除LD_LIBRARY_PATH
:
>> py_import itertools
3125: find library=libpython2.7.so.1.0 [0]; searching
3125: search path=/usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64:/usr/local/MATLAB/R2011a/bin/glnxa64:/usr/local/MATLAB/R2011a/bin/glnxa64/../../sys/os/glnxa64 (RPATH from file /usr/local/MATLAB/R2011a/bin/glnxa64/MATLAB)
3125: trying file=/usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libpython2.7.so.1.0
3125: trying file=/usr/local/MATLAB/R2011a/bin/glnxa64/libpython2.7.so.1.0
3125: trying file=/usr/local/MATLAB/R2011a/bin/glnxa64/../../sys/os/glnxa64/libpython2.7.so.1.0
3125: search path=/usr/local/MATLAB/R2011a/sys/os/glnxa64 (LD_LIBRARY_PATH)
3125: trying file=/usr/local/MATLAB/R2011a/sys/os/glnxa64/libpython2.7.so.1.0
3125: search path=/usr/local/MATLAB/R2011a/bin/glnxa64 (RPATH from file /usr/local/MATLAB/R2011a/bin/glnxa64/MATLAB)
3125: trying file=/usr/local/MATLAB/R2011a/bin/glnxa64/libpython2.7.so.1.0
3125: search path=/usr/local/MATLAB/R2011a/extern/lib/glnxa64:/usr/local/MATLAB/R2011a/runtime/glnxa64:/usr/local/MATLAB/R2011a/sys/java/jre/glnxa64/jre/lib/amd64/native_threads:/usr/local/MATLAB/R2011a/sys/java/jre/glnxa64/jre/lib/amd64/server:/usr/local/MATLAB/R2011a/sys/java/jre/glnxa64/jre/lib/amd64 (LD_LIBRARY_PATH)
3125: trying file=/usr/local/MATLAB/R2011a/extern/lib/glnxa64/libpython2.7.so.1.0
3125: trying file=/usr/local/MATLAB/R2011a/runtime/glnxa64/libpython2.7.so.1.0
3125: trying file=/usr/local/MATLAB/R2011a/sys/java/jre/glnxa64/jre/lib/amd64/native_threads/libpython2.7.so.1.0
3125: trying file=/usr/local/MATLAB/R2011a/sys/java/jre/glnxa64/jre/lib/amd64/server/libpython2.7.so.1.0
3125: trying file=/usr/local/MATLAB/R2011a/sys/java/jre/glnxa64/jre/lib/amd64/libpython2.7.so.1.0
3125: search cache=/etc/ld.so.cache
3125: trying file=/lib64/libpython2.7.so.1.0
3125:
3125: find library=libutil.so.1 [0]; searching
3125: search path=/usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64:/usr/local/MATLAB/R2011a/bin/glnxa64:/usr/local/MATLAB/R2011a/bin/glnxa64/../../sys/os/glnxa64 (RPATH from file /usr/local/MATLAB/R2011a/bin/glnxa64/MATLAB)
3125: trying file=/usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libutil.so.1
3125: trying file=/usr/local/MATLAB/R2011a/bin/glnxa64/libutil.so.1
3125: trying file=/usr/local/MATLAB/R2011a/bin/glnxa64/../../sys/os/glnxa64/libutil.so.1
3125: search path=/usr/local/MATLAB/R2011a/sys/os/glnxa64 (LD_LIBRARY_PATH)
3125: trying file=/usr/local/MATLAB/R2011a/sys/os/glnxa64/libutil.so.1
3125: search path=/usr/local/MATLAB/R2011a/bin/glnxa64 (RPATH from file /usr/local/MATLAB/R2011a/bin/glnxa64/MATLAB)
3125: trying file=/usr/local/MATLAB/R2011a/bin/glnxa64/libutil.so.1
3125: search path=/usr/local/MATLAB/R2011a/extern/lib/glnxa64:/usr/local/MATLAB/R2011a/runtime/glnxa64:/usr/local/MATLAB/R2011a/sys/java/jre/glnxa64/jre/lib/amd64/native_threads:/usr/local/MATLAB/R2011a/sys/java/jre/glnxa64/jre/lib/amd64/server:/usr/local/MATLAB/R2011a/sys/java/jre/glnxa64/jre/lib/amd64 (LD_LIBRARY_PATH)
3125: trying file=/usr/local/MATLAB/R2011a/extern/lib/glnxa64/libutil.so.1
3125: trying file=/usr/local/MATLAB/R2011a/runtime/glnxa64/libutil.so.1
3125: trying file=/usr/local/MATLAB/R2011a/sys/java/jre/glnxa64/jre/lib/amd64/native_threads/libutil.so.1
3125: trying file=/usr/local/MATLAB/R2011a/sys/java/jre/glnxa64/jre/lib/amd64/server/libutil.so.1
3125: trying file=/usr/local/MATLAB/R2011a/sys/java/jre/glnxa64/jre/lib/amd64/libutil.so.1
3125: search cache=/etc/ld.so.cache
3125: trying file=/lib64/libutil.so.1
3125:
3125:
3125: calling init: /lib64/libutil.so.1
3125:
3125:
3125: calling init: /lib64/libpython2.7.so.1.0
3125:
3125:
3125: calling init: /home/cgranade/academics/software-projects/pymex-embed/src/pymex_fns.mexa64
3125:
3125: /home/cgranade/academics/software-projects/pymex-embed/src/pymex_fns.mexa64: error: symbol lookup error: undefined symbol: mexLibrary (fatal)
3125: /usr/lib64/python2.7/lib-dynload/itertoolsmodule.so: error: symbol lookup error: undefined symbol: PyTuple_Type (fatal)
最佳答案
尝试从 MATLAB 内部和系统 shell 运行常规 python:
$ LD_DEBUG_OUTPUT=./ld_debug_out LD_DEBUG=all python -c 'import numpy'
>> !LD_DEBUG_OUTPUT=./ld_debug_out LD_DEBUG=all python -c 'import numpy'
并检查输出文件(也许 all
信息太多了!)。请注意,我导入了 numpy
,因为 itertools
在我的安装中没有相应的共享库..
一个想法是在调用 Py_Initialize()
之前尝试在 MEX 函数中手动加载共享库:
dlopen('libpython2.7.so', RTLD_GLOBAL|RTLD_LAZY);
我在 Windows 机器上,但上次玩这个时我也遇到了一些问题。我记得一旦导入,某些 C 扩展模块就无法在同一 session 中卸载和重新加载(在嵌入 Python 的托管进程的生命周期内)。查看这些 remarks及相关PEP .
关于python - Linux 上的 MATLAB MEX 文件无法在 libpython.2.7.so 中找到符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18541498/
在 this question 的后续问题中,我的企业环境缺少 libpython2.6.so 共享对象,但有 libpython2.6.a 文件。有没有一种方法可以在 libpython2.6.a
构建 rPython 包时,我在 R 中遇到错误,特别是链接 libpython2.7 的部分: gcc -std=gnu99 -I/foo/bar/R-3.1.1/lib64/R/include -
我有一个同时嵌入了 python2 和 python3 解释器的程序。 libpython 共享库由提供对解释器的访问权限的相应命令dlopen()编辑,每个解释器维护自己的状态。 如果用户只使用纯
我没有让 vim 与 python 支持一起工作。我使用以下配置编译 vim 7.4.972: ./configure --enable-shared --with-features=huge --e
在较新的 Ubuntu/Debian 版本下,libpython2.7.so 位于 /usr/lib/i386-linux-gnu/libpython2.7.so 或 /usr/lib/x86_64-
我在 CentOS 5 上安装 Python 2.7。我构建并安装了 Python,如下所示 ./configure --enable-shared --prefix=/usr/local make
我在 macOS 上使用 Conda,在构建 Rust 包时遇到错误,它找不到 libpython3.7m.dylib 库。我怎样才能找到它? 经过一些研究,在 Linux 上,您通常可以从 Ubun
Following the instructions on the PyCall.jl readme ,在我的 julia 项目(在它自己的环境中)使用 PyCall 时,我想使用 pipelinen
我正在运行 arch,在我之前设置的一个项目中,我使用 virtualenv 设置了一个小 python 沙箱。此时,我的机器上的默认 python 版本是 3.2 它已经升级到 3.3,但是当我进入
我正在构建 vim 的 YouCompleteMe 插件,遵循这个 document .当我运行 make 时,出现以下错误。 Linking CXX shared library /home/sag
我在 iOS 应用程序中嵌入了 libPython.a,我正在使用 PyRun_SimpleFileEx 运行脚本: Py_SetPythonHome((char *)[resourcePat
是否有任何独立于平台的方法来获取 python 安装的 libpython 的路径,以用作 cmake 参数? sysconfig.get_config_var 提供了一些片段,但我没有一致的方法可以
我问了另一个问题,这个问题太复杂了,无法直接回答,所以我把它归结为这个基本问题...... 当我使用标准的 cython distutils 构建我的 aModule.so 时,它似乎没有链接到 li
我一直在研究 project使用 libpython2.7.so 将 Python 解释器作为 MEX 文件嵌入到 MATLAB 中,但是每当我尝试导入作为扩展模块实现的 Python 模块时都会遇到
我正在尝试在 arm 设备的嵌入式解释器中运行 python 代码;使用 marmalade studio 在 visual studio 2012 中构建。 我已经构建了我的存档静态链接库,li
我正在尝试在我的代码中记录热点,以便能够使用多线程对其进行优化。 我首先运行在容器外安装了 pyflame sudo apt-get install autoconf automake autotoo
我是一名优秀的程序员,十分优秀!