有关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不一样,所以有没有知道原因和解决方案的大牛,还望指点一二。