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 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条