MingVip8 2020-03-10 11:54 采纳率: 0%
浏览 1281

Linux环境下,在Qt中调用Python,导入第三方库时出错?

有关python的文件列表如下:
图片说明

在Terminal中用python解释器运行时完全正常:
图片说明

在把该py文件加入Qt项目后,运行时出错。
图片说明
以下是python的调用代码:

    //【1】初始化
    Py_Initialize();
    if (!Py_IsInitialized())
    {
        qDebug() << "init python failed";
        return;
    }

    //【2】添加python模块路径
    PyRun_SimpleString("import sys");
    PyRun_SimpleString("sys.path.append('/root/IOLTest/')");

    //【3】导入python模块
    PyObject* pModule = PyImport_ImportModule("bandpass");
    if (!pModule)
    {
        qDebug() << "import module bandpass failed";
        return;
    }

    //【4】获取python函数
    PyObject* pFunhello= PyObject_GetAttrString(pModule,"hello");
    if(!pFunhello)
    {
        qDebug() << "call hello failed";
        return;
    }

    //【5】调用python函数
    PyObject_CallObject(pFunhello,NULL);


    //【6】释放python组件
    Py_Finalize();

程序运行到第三步导入python模块时出错,try-except打印的信息是:

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

Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
  1. Check that you expected to use Python3.6 from "/usr/bin/python3",
     and that you have no directories in your PATH or PYTHONPATH that can
     interfere with the Python and numpy version "1.18.1" you're trying to use.
  2. If (1) looks fine, you can open a new issue at
     https://github.com/numpy/numpy/issues.  Please include details on:
     - how you installed Python
     - how you installed numpy
     - your operating system
     - whether or not you have multiple versions of Python installed
     - if you built from source, your compiler versions and ideally a build log

- If you're working with a numpy git repository, try `git clean -xdf`
  (removes all files not under version control) and rebuild numpy.

Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.

Original error was: /usr/local/lib/python3.6/dist-packages/numpy/core/_multiarray_umath.cpython-36m-x86_64-linux-gnu.so: undefined symbol: PyExc_ImportError

问题出在导入第三方库上,即 import scipy.signal as signal 这行代码,若是去掉,则可以正常运行。
貌似是Qt里的环境跟Terminal不一样,所以有没有知道原因和解决方案的大牛,还望指点一二。

  • 写回答

1条回答

  • CSDN-Ada助手 CSDN-AI 官方账号 2022-09-09 19:38
    关注
    不知道你这个问题是否已经解决, 如果还没有解决的话:

    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 以帮助更多的人 ^-^
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?