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 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法
  • ¥15 很想要一个很好的答案或提示
  • ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr
  • ¥15 怀疑手机被监控,请问怎么解决和防止
  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区