Hadi Moghaddar
Hadi Moghaddar

Reputation: 125

Using numpy module in pythonQt

I want to use python(especially numpy pkg) in Qt, so I use PythonQt for this purpose. Since I need numpy python module I use this flags to initial PythonQt.

PythonQt::init(PythonQt::ExternalHelp);

For testing numpy I use simple sample test as you can see below

int main(int argc, char *argv[]){
    QCoreApplication a(argc,argv);
    PythonQt::init(PythonQt::ExternalHelp);
    PythonQtObjectPtr  context=PythonQt::self()->getMainModule();
    context.evalScript("import numpy\ndef mul(a,b):\n  return a*b");
    QVariantList args;
    args<<42<<2;
    QVariant result=context.call("mul",args);
    qDebug()<<result.toString();
    return a.exec();
}

When I run above simple code, it raise this error : File "/usr/local/lib/python-64bit-3.4.3/lib/site-packages/numpy/core/init.py", line 5, in ImportError: No module named multiarray

I also create a simple project in c++ and add python.h header file and python lib directory to my project in order to test numpy. the result was ok and everything work correctly, but in PythonQt it doesn’t work. I searched alot for this error and none of them solved my problem.

I need to solve this problem immediately so tanks for helping

Upvotes: 3

Views: 739

Answers (1)

Hadi Moghaddar
Hadi Moghaddar

Reputation: 125

finally after a lot of attempting to solving this problem i founded that PythonQt should build in release mode to working correctly(as mention in documention of pythonQt). since i compile python3.4,I could debugging PythonQt because i build PythonQt in Debuging mode it generate PythonQt.pdb file for me, but in debug mode it doesn't work correctly. I leave this post for who one comes with the same problem.

Upvotes: 3

Related Questions