1

I intent to use Anaconda's Python in my Qt C++ application to call some scikit-learn algorithms from within my C++ code. For some reason I cannot figure out how to do the integration. I wonder if anybody knows a step by step procedure to do so.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Megidd
  • 7,089
  • 6
  • 65
  • 142

2 Answers2

2

If your C++ code works with Qt <= 5.9.7. (or more precisely Anaconda's current Qt version) you can include Python (in this case 3.6) by adding

INCLUDEPATH += /home/[username]/anaconda3/include/python3.6m

LIBS += -L/home/[username]/anaconda3/lib/ -lpython3.6m

to your .pro file.

If you need a Qt version which is higher than the one provided by Anaconda, have a look at my question here. Now you should be able to include the Python.h header in your application.

Remark: Keep in mind that Python provides its own signals and slots mechanism which can apparently clash with Qt's. That's why I added

CONFIG += no_keywords

to my pro file, and replaced all signals and slots occurrences like described here.

Florian Blume
  • 3,237
  • 17
  • 37
1

I am not sure this would work for you, but I'd look at this article. It provides at least a way to start a python interpreter from within the Qt application.

I think this might work, depending on the complexity of the thing.

You can find more on the PythonQt.

I don't know how well it will work with external packages though.

Otherwise, you could use PySide2, which allows you to create GUIs using Qt5 framework in python.

I hope it helps.

Sysmetryx
  • 33
  • 6