Fuzzy copies are imported from the multiarray extension library when called from embedded Python in a C ++ application

I am running a C ++ application that is trying to start python using function calls https://docs.python.org/3.5/extending/embedding.html . This is the error that application error message channels give me.

class 'ImportError': Failed to import an extension module with multiple arrays. Most likely you are trying to import a failed numpy build. If you work with git clean -xdfgit, try git clean -xdf(deletes all files that are not under version control). Otherwise reinstall NumPy.

Initial error: /usr/local/lib/python3.5/site-packages/numpy/core/multiarray.cpython-35m-x86_64-linux-gnu.so: undefined character: PyExc_UserWarning

I am very puzzled since this only happens when embedding Python in C ++, since importing works when I use it through an interpreter. I'm more interested in an answer that adds to my understanding than a quick execution or fix. I list some system / problem information below and some other questions that I am going to post on the same topic. Any guidance is appreciated!

System / Problem Information:

  • Ubuntu 16.04, 64 bit
  • Compiled Python 3.5.5 with sharing enabled
  • numpy import works in the interpreter (python3.exe and python3.5.exe)
  • , PySys_SetPath() sys.path, : import sys, sys.path
  • , PIL datetimeutil; , NumPy (Pandas NumPy , )
  • Python : Py_Import_Import(), Py_Initialize() ( . .) .., .
  • CMake, MakeFiles .
  • numpy-1.14.2 pip 9.0.0 pip3.5 install numpy
  • python, , : import numpy...
  • .zip, .
  • .Exe, Python, C++, /usr/local/bin/python3 ( Py_GetProgramName()). .exe libpython3.5m.so.1.0, libpython3.5m.so.1.0 ( )
  • ldd multiarray.cpython-35m-x86_64-linux-gnu.so :

    ldd multiarray.cpython-35m-x86_64-linux-gnu.so

    linux-vdso.so.1 => (0x00007ffd9e36b000)

    libopenblasp-r0-39a31c03.2.18.so => /usr/local/lib/python3.5/site-packages/numpy/core/./../.libs/libopenblasp-r0-39a31c03.2.18.so(0x00007fdbe149b000)

    libm.so.6 =>/lib/x86_64-linux-gnu/libm.so.6 (0x00007fdbe1192000)

    libpthread.so.0 =>/lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fdbe0f75000) libc.so.6 =>/lib/x86_64-linux-gnu/libc.so.6 (0x00007fdbe0bab000)/lib64/ld-linux-x86-64.so.2 (0x00007fdbe3ed5000)

    libgfortran-ed201abd.so.3.0.0 =>/usr/local/lib/python3.5/site-packages/numpy/core/./../.libs/libgfortran-ed201abd.so.3.0.0 (0x00007fdbe08b1000)

/ NUMPY , , .

, , - . , numpy Python C++; , , , , . , , , , , . , , / ( , ).

  • multiarray.so pythonX.X.so ? , , - .
  • CMake , , , 4/12/18 16/16/18.
  • PYTHONPATH .bashrc, , , Py_GetPath(), sys.path. bash, C++.

, , .

, , . .

: 17.04.18:

, , . , / , . Numpy, , - . , - . , . , pythonInterface.cpp:

  • #include <dlfcn.h>
  • dlopen("libpython3.5m.so.1.0", RTLD_LAZY | RTLD_GLOBAL)

, cpython.multiarray.so.

, .so, . , , python, pythonInterface.so , . , , , . !

+8
1

- multiarray.cpython-35m-x86_64-linux-gnu.so multiarray.cpython-35m-x86_64-linux-gnu.so numpy libpythonx.x.so, libpythonx.x.so. , ldd -d multiarray.cpython-35m-x86_64-linux-gnu.so .

Python , python libpython.xxso, , numpy multiarray.cpython-35m-x86_64-linux-gnu.so, dlopen. libdl.so , - python. libpython.xxso.

, , libdl.so libpython.xxso. :

  1. dlopen("libpythonx.x.so", RTLD_GLOBAL). , RTLD_GLOBAL, libpythonx.x.so .
  2. , libpythonx.x.so python, libpythonx.x.so .
0

Source: https://habr.com/ru/post/1696079/


All Articles