-->

ubuntu20.4中c#通过c++库调用python脚本

2021-01-13 17:41发布

问题:

求问各位大佬,下面这个问题如何解决呀?????
问题描述:

1:在qt中创建了一个c++库(libraryDemo.so)用于调用python脚本文件,如下所示:

2:在qt中创建一个c++项目,调用ibraryDemo.so库,可以正常运行出结果:

3:在vscode中调用ibraryDemo.so库运行报错:

错误提示:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/numpy/core/init.py", line 22, in <module>
from . import multiarray
File "/usr/local/lib/python3.8/dist-packages/numpy/core/multiarray.py", line 12, in <module>
from . import overrides
File "/usr/local/lib/python3.8/dist-packages/numpy/core/overrides.py", line 7, in <module>
from numpy.core._multiarray_umath import (
ImportError: /usr/local/lib/python3.8/dist-packages/numpy/core/_multiarray_umath.cpython-38-x86_64-linux-gnu.so: undefined symbol: PyExc_RecursionError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/numpy/init.py", line 140, in <module>
from . import core
File "/usr/local/lib/python3.8/dist-packages/numpy/core/init.py", line 48, in <module>
raise ImportError(msg)
ImportError:

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  • The Python version is: Python3.8 from "/usr/bin/python3"
  • The NumPy version is: "1.19.5"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: /usr/local/lib/python3.8/dist-packages/numpy/core/_multiarray_umath.cpython-38-x86_64-linux-gnu.so: undefined symbol: PyExc_RecursionError

操作系统安装的python和numpy版本:

回答1:

C#和C++调用的运行环境估计还是有差别的。
https://github.com/numpy/numpy/issues/14946
https://stackoverflow.com/questions/49784583/numpy-import-fails-on-multiarray-extension-library-when-called-from-embedded-pyt
这里有个类似的问题,既然报_multiarray_umath.cpython-38-x86_64-linux-gnu.so这个so的问题,估计某些库的搜索模式有差别



回答2:

so调用要用有个手机的虚拟环境,他是so文件是安卓开发的动态库



标签: c# qt c++ python