首页 新闻 会员 周边 捐助

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

0
悬赏园豆:200 [已解决问题] 解决于 2021-01-13 17:52

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

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版本:

问题补充:

我现在怀疑是环境变量的问题,但是不清楚具体是哪里出了问题,这个系统里面的python环境我是用的自带的,只是装了一个python3.8-dev

JoyandJoys的主页 JoyandJoys | 初学一级 | 园豆:22
提问于:2021-01-11 18:02
< >
分享
最佳答案
0

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的问题,估计某些库的搜索模式有差别

收获园豆:100
2012 | 高人七级 |园豆:21645 | 2021-01-11 18:48

按照这上面的说法改了一下,还是一样的报错耶

JoyandJoys | 园豆:22 (初学一级) | 2021-01-11 21:27
其他回答(1)
0

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

收获园豆:100
小小咸鱼YwY | 园豆:3312 (老鸟四级) | 2021-01-11 18:35

嗯???不是很明白

支持(0) 反对(0) JoyandJoys | 园豆:22 (初学一级) | 2021-01-11 18:42

@JoyandJoys: python运行so文件必须要安卓环境结合hook进行调用,不能直接调用,你可以把这so文件简单些一个app中,然后fridahook这个so方法,起服务,调用就好了

支持(0) 反对(0) 小小咸鱼YwY | 园豆:3312 (老鸟四级) | 2021-01-12 09:27

@小小咸鱼YwY: 那为什么c++调用就可以正常使用呢???

支持(0) 反对(0) JoyandJoys | 园豆:22 (初学一级) | 2021-01-12 21:48

@JoyandJoys: 很正常啊,so本来就可以用c++运行,只要他so文件不加壳一点问题都没有

支持(0) 反对(0) 小小咸鱼YwY | 园豆:3312 (老鸟四级) | 2021-01-13 09:17

@小小咸鱼YwY: 如果我代码里面不用numpy相关的函数,c#也是可以正常通过库访问到python脚本里面,这样就不符合您所说的要加一个壳的步骤呀。

支持(0) 反对(0) JoyandJoys | 园豆:22 (初学一级) | 2021-01-13 12:19

@JoyandJoys: - -,我们说的完全不是一个话题,简单来说python运行 so文件就要安卓环境信不信由你,也不废话

支持(0) 反对(0) 小小咸鱼YwY | 园豆:3312 (老鸟四级) | 2021-01-13 14:36

@JoyandJoys: python底层还是c写的,c能调用python,python不一定调用c

支持(0) 反对(0) 小小咸鱼YwY | 园豆:3312 (老鸟四级) | 2021-01-13 14:38

@小小咸鱼YwY: 嗯嗯,谢谢您的解答,这个问题已经解决啦

支持(0) 反对(0) JoyandJoys | 园豆:22 (初学一级) | 2021-01-13 17:51
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册