Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Trying to call python functions from my GUI, compiler is out of heap space
Forum Updated to NodeBB v4.3 + New Features

Trying to call python functions from my GUI, compiler is out of heap space

Scheduled Pinned Locked Moved Unsolved General and Desktop
17 Posts 4 Posters 1.4k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SGaist
    Lifetime Qt Champion
    wrote on 24 Aug 2021, 20:13 last edited by
    #2

    Hi,

    Why are you including both since you want to use pybind11 ?

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    L 1 Reply Last reply 24 Aug 2021, 20:17
    0
    • S SGaist
      24 Aug 2021, 20:13

      Hi,

      Why are you including both since you want to use pybind11 ?

      L Offline
      L Offline
      lfreeman6490
      wrote on 24 Aug 2021, 20:17 last edited by lfreeman6490
      #3

      @SGaist I was told I needed both. Getting rid of the 'python.h' import and leaving in the 'pybind11' import does not get rid of the error. Getting rid of pybind11 but leaving in python.h does get rid of the error

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 24 Aug 2021, 21:28 last edited by
        #4

        Which compiler are you using ?
        On which platform ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        L 1 Reply Last reply 25 Aug 2021, 13:30
        1
        • S SGaist
          24 Aug 2021, 21:28

          Which compiler are you using ?
          On which platform ?

          L Offline
          L Offline
          lfreeman6490
          wrote on 25 Aug 2021, 13:30 last edited by
          #5

          @SGaist I'm using QTCreator v3.0.1
          c++ GUI
          windows 10
          32bit python 2.7

          M 1 Reply Last reply 25 Aug 2021, 13:56
          0
          • L lfreeman6490
            25 Aug 2021, 13:30

            @SGaist I'm using QTCreator v3.0.1
            c++ GUI
            windows 10
            32bit python 2.7

            M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 25 Aug 2021, 13:56 last edited by
            #6

            @lfreeman6490

            Hi and which compiler mingw or visual studio ?

            L 1 Reply Last reply 25 Aug 2021, 14:04
            0
            • M mrjj
              25 Aug 2021, 13:56

              @lfreeman6490

              Hi and which compiler mingw or visual studio ?

              L Offline
              L Offline
              lfreeman6490
              wrote on 25 Aug 2021, 14:04 last edited by
              #7

              @mrjj mingw

              M 1 Reply Last reply 25 Aug 2021, 14:08
              0
              • L lfreeman6490
                25 Aug 2021, 14:04

                @mrjj mingw

                M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 25 Aug 2021, 14:08 last edited by
                #8

                @lfreeman6490
                Hi
                Im not sure if that is supported.
                https://github.com/pybind/pybind11

                Its not listed in compilers.

                Also is this 32 bit mingw ?
                or 64 ?

                L 1 Reply Last reply 25 Aug 2021, 14:10
                0
                • M mrjj
                  25 Aug 2021, 14:08

                  @lfreeman6490
                  Hi
                  Im not sure if that is supported.
                  https://github.com/pybind/pybind11

                  Its not listed in compilers.

                  Also is this 32 bit mingw ?
                  or 64 ?

                  L Offline
                  L Offline
                  lfreeman6490
                  wrote on 25 Aug 2021, 14:10 last edited by
                  #9

                  @mrjj It's 32 bit, I used pip to install it. If it is not supported are you aware of another way that I can call python functions?

                  M 1 Reply Last reply 25 Aug 2021, 15:00
                  0
                  • L lfreeman6490
                    25 Aug 2021, 14:10

                    @mrjj It's 32 bit, I used pip to install it. If it is not supported are you aware of another way that I can call python functions?

                    M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 25 Aug 2021, 15:00 last edited by
                    #10

                    @lfreeman6490

                    From link
                    3, Microsoft Visual Studio 2015 Update 3 or newer

                    It does support visual studio 2015 it seems so that might work with 32 bit.

                    So you could install vs 2015 compiler if that can work with your app ?

                    L 1 Reply Last reply 25 Aug 2021, 15:13
                    0
                    • M mrjj
                      25 Aug 2021, 15:00

                      @lfreeman6490

                      From link
                      3, Microsoft Visual Studio 2015 Update 3 or newer

                      It does support visual studio 2015 it seems so that might work with 32 bit.

                      So you could install vs 2015 compiler if that can work with your app ?

                      L Offline
                      L Offline
                      lfreeman6490
                      wrote on 25 Aug 2021, 15:13 last edited by lfreeman6490
                      #11

                      @mrjj I've been headed this direction and I ditched pybind11, I have been able to get my python file to compile, but not much after that. My file is "test_py_file" and my function is "test_function". There are no errors being thrown at the moment, but also it is not executing the function.

                      void f_pathloss::on_pb_tester_connect_disconnect_clicked()
                      {
                      
                          PyObject *pName, *pModule, *pDict, *pFunc, *pValue, *presult;
                      
                          Py_Initialize();
                          pName = PyString_FromString((char*)"test_py_file");
                          pModule = PyImport_Import(pName);
                          pDict = PyModule_GetDict(pModule);
                      
                          pFunc = PyDict_GetItemString(pDict, (char*)"test_function");
                      
                      
                          Py_Finalize();
                      }
                      
                      J 1 Reply Last reply 25 Aug 2021, 15:52
                      0
                      • L lfreeman6490
                        25 Aug 2021, 15:13

                        @mrjj I've been headed this direction and I ditched pybind11, I have been able to get my python file to compile, but not much after that. My file is "test_py_file" and my function is "test_function". There are no errors being thrown at the moment, but also it is not executing the function.

                        void f_pathloss::on_pb_tester_connect_disconnect_clicked()
                        {
                        
                            PyObject *pName, *pModule, *pDict, *pFunc, *pValue, *presult;
                        
                            Py_Initialize();
                            pName = PyString_FromString((char*)"test_py_file");
                            pModule = PyImport_Import(pName);
                            pDict = PyModule_GetDict(pModule);
                        
                            pFunc = PyDict_GetItemString(pDict, (char*)"test_function");
                        
                        
                            Py_Finalize();
                        }
                        
                        J Offline
                        J Offline
                        JonB
                        wrote on 25 Aug 2021, 15:52 last edited by JonB
                        #12

                        @lfreeman6490
                        You pasted this code elsewhere with the same comment. How do you/we know it is doing nothing? And I asked you whether you really have test_py_file and test_function in it, else what do you expect?

                        And I also suggested you try a different example @mrjj had quoted you.

                        It helps if we keep the same question in one thread....

                        1 Reply Last reply
                        2
                        • M Offline
                          M Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on 25 Aug 2021, 19:25 last edited by mrjj
                          #13

                          Hi
                          There is something missing

                          pFunc = PyDict_GetItemString(pDict, (char*)"test_function");

                          this gets you a function pointer but you do not call it.

                          something like
                          PyObject* myResult = PyObject_CallObject(pFunc , args)

                          args can be NULL if none is needed

                          L 1 Reply Last reply 26 Aug 2021, 17:59
                          1
                          • M mrjj
                            25 Aug 2021, 19:25

                            Hi
                            There is something missing

                            pFunc = PyDict_GetItemString(pDict, (char*)"test_function");

                            this gets you a function pointer but you do not call it.

                            something like
                            PyObject* myResult = PyObject_CallObject(pFunc , args)

                            args can be NULL if none is needed

                            L Offline
                            L Offline
                            lfreeman6490
                            wrote on 26 Aug 2021, 17:59 last edited by
                            #14

                            @mrjj I decided to use pybind11, I'm still fighting off errors this way but it seems better. Thank you for the suggestions

                            M 1 Reply Last reply 26 Aug 2021, 18:29
                            0
                            • L lfreeman6490
                              26 Aug 2021, 17:59

                              @mrjj I decided to use pybind11, I'm still fighting off errors this way but it seems better. Thank you for the suggestions

                              M Offline
                              M Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on 26 Aug 2021, 18:29 last edited by
                              #15

                              Hi
                              Well pybind11 is harder to get going but will be much nicer code-wise than the PyObject_xxxx interface for a more
                              complete integration but If you only need to call one function in python, pyBind11 might be a little overkill but
                              is then very future proof.

                              L 1 Reply Last reply 26 Aug 2021, 20:36
                              0
                              • M mrjj
                                26 Aug 2021, 18:29

                                Hi
                                Well pybind11 is harder to get going but will be much nicer code-wise than the PyObject_xxxx interface for a more
                                complete integration but If you only need to call one function in python, pyBind11 might be a little overkill but
                                is then very future proof.

                                L Offline
                                L Offline
                                lfreeman6490
                                wrote on 26 Aug 2021, 20:36 last edited by
                                #16

                                @mrjj yeah I've been struggling with pybind11 a ton so far. Haven't gotten much of anywhere really. But I am going to need to use a decent amount of functions from the Python file

                                M 1 Reply Last reply 27 Aug 2021, 05:39
                                0
                                • L lfreeman6490
                                  26 Aug 2021, 20:36

                                  @mrjj yeah I've been struggling with pybind11 a ton so far. Haven't gotten much of anywhere really. But I am going to need to use a decent amount of functions from the Python file

                                  M Offline
                                  M Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on 27 Aug 2021, 05:39 last edited by
                                  #17

                                  @lfreeman6490

                                  Hi
                                  What kind of errors ?

                                  make sure to read the docs as its a bit hysteric with the compilers
                                  https://pybind11.readthedocs.io/en/stable/basics.html

                                  The PyObject_CallObject API didnt work for you or why did you give it up so fast ?

                                  1 Reply Last reply
                                  0

                                  11/17

                                  25 Aug 2021, 15:13

                                  • Login

                                  • Login or register to search.
                                  11 out of 17
                                  • First post
                                    11/17
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • Users
                                  • Groups
                                  • Search
                                  • Get Qt Extensions
                                  • Unsolved