Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How to run external QT program from PyQT5 on MacOS
Forum Update on Monday, May 27th 2025

How to run external QT program from PyQT5 on MacOS

Scheduled Pinned Locked Moved Unsolved Qt for Python
29 Posts 3 Posters 3.7k Views
  • 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.
  • B Offline
    B Offline
    Benjamin Halko
    wrote on 13 Jan 2022, 21:16 last edited by
    #1

    When trying to run a QT program from PyQT5 the external program crashes and says that qt.qpa.plugin: Could not load the Qt platform plugin "{a platform}" in "" even though it was found. This is probably because it is trying to load 2 sets of libraries, one from my app and one from the external programs.

    On Windows this can be fix by setting QT_QPA_PLATFORM_PLUGIN_PATH to the plugin path in the folder, but on MacOS I can't seem to get it working on MacOS, is there an easier way of running a program in PyQT5 than this?

    By the way, the program I am trying to run is the Dolphin Emulator.

    Windows Code:

    env = os.environ
    env["QT_QPA_PLATFORM_PLUGIN_PATH"] = os.path.dirname(programPath)+'/QtPlugins/platforms/'
    subprocess.Popen(programPath,env=env)
    

    MacOS Code:

    env = os.environ
    env["QT_QPA_PLATFORM_PLUGIN_PATH"] = programPath+'/Contents/MacOS/platforms/'
    subprocess.Popen(programPath+'/Contents/MacOS/Dolphin',env=env)
    
    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 13 Jan 2022, 21:21 last edited by
      #2

      Hi and welcome to devnet,

      Why not start the application through the app bundle rather than going inside it to the executable ?

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

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Benjamin Halko
        wrote on 13 Jan 2022, 21:26 last edited by
        #3

        When I try doing that it tells me permission denied.

        Here's where I got that fix from: https://stackoverflow.com/questions/23353472/permission-denied-opening-application-in-python-shell

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 13 Jan 2022, 21:28 last edited by
          #4

          Ok, in that case I would use the open shell command and pass it the path to the bundle.

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

          B 1 Reply Last reply 15 Jan 2022, 00:32
          0
          • B Offline
            B Offline
            Benjamin Halko
            wrote on 13 Jan 2022, 21:36 last edited by
            #5

            Ok thanks, I will try that out!

            1 Reply Last reply
            0
            • S SGaist
              13 Jan 2022, 21:28

              Ok, in that case I would use the open shell command and pass it the path to the bundle.

              B Offline
              B Offline
              Benjamin Halko
              wrote on 15 Jan 2022, 00:32 last edited by Benjamin Halko
              #6

              @SGaist I tried it out, and it gave me LSOpenURLsWithRole() failed with error -10810 for the file /Users/benjamin/Desktop/Dolphin.app.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 15 Jan 2022, 20:09 last edited by
                #7

                @Benjamin-Halko said in How to run external QT program from PyQT5 on MacOS:

                LSOpenURLsWithRole() failed with error -10810

                Are you hitting the situation described here ?

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

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  Benjamin Halko
                  wrote on 15 Jan 2022, 22:23 last edited by Benjamin Halko
                  #8

                  @SGaist Yes that is actually the problem I am running into. Dolphin does not like being a child process of my program. Does QT have a simple solution to this problem?

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 16 Jan 2022, 20:14 last edited by
                    #9

                    Does it only happen with Dolphin ?
                    By the way, why Dolphin on macOS rather than Finder ?

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

                    1 Reply Last reply
                    0
                    • B Offline
                      B Offline
                      Benjamin Halko
                      wrote on 17 Jan 2022, 00:20 last edited by
                      #10

                      Well Dolphin is the only .app I am trying to open with my program, so I wouldn't know if this happens with other programs.

                      What do you mean by macOS rather than Finder?

                      J 1 Reply Last reply 17 Jan 2022, 08:51
                      0
                      • B Benjamin Halko
                        17 Jan 2022, 00:20

                        Well Dolphin is the only .app I am trying to open with my program, so I wouldn't know if this happens with other programs.

                        What do you mean by macOS rather than Finder?

                        J Offline
                        J Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on 17 Jan 2022, 08:51 last edited by
                        #11

                        @Benjamin-Halko said in How to run external QT program from PyQT5 on MacOS:

                        What do you mean by macOS rather than Finder?

                        The file manager on MacOS is called Finder. There is no Dolphin unless you install it.

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0
                        • B Offline
                          B Offline
                          Benjamin Halko
                          wrote on 17 Jan 2022, 16:43 last edited by Benjamin Halko
                          #12

                          @jsulm Yeah finder is installed. By Finder rather than MacOS do you mean telling finder to open Dolphin Emulator rather than just tell MacOS to open it?

                          Oh and Dolphin works just fine when running it from Finder normally, it is just when I launch it using subprocess.Popen that is the trouble.

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 17 Jan 2022, 18:47 last edited by
                            #13

                            From the looks of it, we are talking about very different software.

                            "Dolphin" is known to be the KDE file manager. So from the looks of it you are trying to start something very different. Can you give more details about what it is ? And what exactly you are trying to do with your application ?

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

                            B 1 Reply Last reply 17 Jan 2022, 20:02
                            0
                            • S SGaist
                              17 Jan 2022, 18:47

                              From the looks of it, we are talking about very different software.

                              "Dolphin" is known to be the KDE file manager. So from the looks of it you are trying to start something very different. Can you give more details about what it is ? And what exactly you are trying to do with your application ?

                              B Offline
                              B Offline
                              Benjamin Halko
                              wrote on 17 Jan 2022, 20:02 last edited by
                              #14

                              @SGaist I am wanting to open the Dolphin Emulator from my app as well as tell it to load a game using the -e argument that it accepts. However since Dolphin is also a QT program when trying to run it using subprocess, it tries loading both sets of libraries (from my app and Dolphin)

                              1 Reply Last reply
                              0
                              • S Offline
                                S Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on 17 Jan 2022, 20:10 last edited by
                                #15

                                What if you use the QProcess::startDetached method ?

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

                                B 2 Replies Last reply 18 Jan 2022, 00:33
                                0
                                • S SGaist
                                  17 Jan 2022, 20:10

                                  What if you use the QProcess::startDetached method ?

                                  B Offline
                                  B Offline
                                  Benjamin Halko
                                  wrote on 18 Jan 2022, 00:33 last edited by Benjamin Halko
                                  #16

                                  @SGaist Ok so I tried and nothing happened! But then I tried using the executable located in /Contents/MacOS/Dolphin
                                  and it gave me this:

                                  objc[2357]: Class QMacAutoReleasePoolTracker is implemented in both /Users/benjamin/Desktop/Dolphin.app/Contents/Frameworks/QtCore.framework/Versions/5/QtCore (0x10b53a9f8) and /private/var/folders/50/g29zbzlx4fb85zh8kk4g6gm40000gn/T/_MEIYRjNbS/QtCore (0x10efe8198). One of the two will be used. Which one is undefined.
                                  objc[2357]: Class QT_ROOT_LEVEL_POOL__THESE_OBJECTS_WILL_BE_RELEASED_WHEN_QAPP_GOES_OUT_OF_SCOPE is implemented in both /Users/benjamin/Desktop/Dolphin.app/Contents/Frameworks/QtCore.framework/Versions/5/QtCore (0x10b53aa70) and /private/var/folders/50/g29zbzlx4fb85zh8kk4g6gm40000gn/T/_MEIYRjNbS/QtCore (0x10efe8210). One of the two will be used. Which one is undefined.
                                  objc[2357]: Class KeyValueObserver is implemented in both /Users/benjamin/Desktop/Dolphin.app/Contents/Frameworks/QtCore.framework/Versions/5/QtCore (0x10b53aa98) and /private/var/folders/50/g29zbzlx4fb85zh8kk4g6gm40000gn/T/_MEIYRjNbS/QtCore (0x10efe8238). One of the two will be used. Which one is undefined.
                                  objc[2357]: Class RunLoopModeTracker is implemented in both /Users/benjamin/Desktop/Dolphin.app/Contents/Frameworks/QtCore.framework/Versions/5/QtCore (0x10b53aae8) and /private/var/folders/50/g29zbzlx4fb85zh8kk4g6gm40000gn/T/_MEIYRjNbS/QtCore (0x10efe8288). One of the two will be used. Which one is undefined.
                                  QObject::moveToThread: Current thread (0x7faab1e065c0) is not the object's thread (0x7faab1c17ed0).
                                  Cannot move to target thread (0x7faab1e065c0)
                                  
                                  You might be loading two sets of Qt binaries into the same process. Check that all plugins are compiled against the right Qt binaries. Export DYLD_PRINT_LIBRARIES=1 and check that only one set of binaries are being loaded.
                                  qt.qpa.plugin: Could not load the Qt platform plugin "cocoa" in "" even though it was found.
                                  This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
                                  
                                  Available platform plugins are: cocoa, minimal, offscreen, webgl.
                                  

                                  This was the code I used:

                                  launch = QProcess()
                                  launch.startDetached(dolphinPath+"/Contents/MacOS/Dolphin")
                                  
                                  1 Reply Last reply
                                  0
                                  • S SGaist
                                    17 Jan 2022, 20:10

                                    What if you use the QProcess::startDetached method ?

                                    B Offline
                                    B Offline
                                    Benjamin Halko
                                    wrote on 19 Jan 2022, 00:01 last edited by
                                    #17

                                    @SGaist Oh by the way, this issue only occurs when the program is packaged with pyinstaller, running it regularly works just fine.

                                    1 Reply Last reply
                                    0
                                    • S Offline
                                      S Offline
                                      SGaist
                                      Lifetime Qt Champion
                                      wrote on 19 Jan 2022, 19:12 last edited by
                                      #18

                                      What exactly are you packaging ?

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

                                      1 Reply Last reply
                                      0
                                      • B Offline
                                        B Offline
                                        Benjamin Halko
                                        wrote on 19 Jan 2022, 23:43 last edited by Benjamin Halko
                                        #19

                                        Here is my project folder. Here is the actual run dolphin function. Hope that helps.

                                        1 Reply Last reply
                                        0
                                        • S Offline
                                          S Offline
                                          SGaist
                                          Lifetime Qt Champion
                                          wrote on 21 Jan 2022, 19:33 last edited by SGaist
                                          #20

                                          Did you try to use Popen with shell=True ?

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

                                          B 1 Reply Last reply 22 Jan 2022, 19:01
                                          0

                                          6/29

                                          15 Jan 2022, 00:32

                                          topic:navigator.unread, 23
                                          • Login

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