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. Unable to successfully import files with mix use of PySide6 and PyQt6
QtWS25 Last Chance

Unable to successfully import files with mix use of PySide6 and PyQt6

Scheduled Pinned Locked Moved Unsolved General and Desktop
22 Posts 3 Posters 2.6k 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.
  • E explorer100
    26 Jul 2024, 10:51

    I am trying to use the tools to show matplotlib plots in the Qt environment.

    I am using a matplotlib canvas using the simple program:

    import sys
    import matplotlib
    matplotlib.use('QtAgg')

    from PyQt6 import QtCore, QtWidgets
    #from PySide6 import QtCore, QtWidgets

    from matplotlib.backends.backend_qtagg import FigureCanvasQTAgg, NavigationToolbar2QT as NavigationToolbar
    from matplotlib.figure import Figure

    class MplCanvas(FigureCanvasQTAgg):

    def __init__(self, parent=None, width=5, height=4, dpi=100):
        fig = Figure(figsize=(width, height), dpi=dpi)
        self.axes = fig.add_subplot(111)
        super(MplCanvas, self).__init__(fig)
    

    class MainWindow(QtWidgets.QMainWindow):

    def __init__(self, *args, **kwargs):
        super(MainWindow, self).__init__(*args, **kwargs)
    
        sc = MplCanvas(self, width=5, height=4, dpi=100)
        sc.axes.plot([0,1,2,3,4], [10,1,20,3,40])
    
        # Create toolbar, passing canvas as first parament, parent (self, the MainWindow) as second.
        toolbar = NavigationToolbar(sc, self)
    
        layout = QtWidgets.QVBoxLayout()
        layout.addWidget(toolbar)
        layout.addWidget(sc)
    
        # Create a placeholder widget to hold our toolbar and canvas.
        widget = QtWidgets.QWidget()
        widget.setLayout(layout)
        self.setCentralWidget(widget)
    
        self.show()
    

    def show_a_static_plot():

    app = QtWidgets.QApplication(sys.argv)
    w = MainWindow()
    app.exec()
    

    and run it with:

    import sys
    #from PyQt6.QtWidgets import QApplication
    from PySide6 import QtCore
    from qt_matplotlib_canvas import show_a_static_plot
    app = QApplication(sys.argv)
    show_a_static_plot()

    when the import is from PySide:
    the interpreter result is:

    from PyQt6 import QtCore, QtWidgets
    

    ImportError: DLL load failed while importing QtCore: The specified procedure could not be found.

    E Offline
    E Offline
    explorer100
    wrote on 26 Jul 2024, 11:01 last edited by
    #2

    The issue is:

    The utility is using PyQt6 imports while PySide generated ui. files are using Pyside imports.

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 26 Jul 2024, 11:07 last edited by
      #3

      Why don't you use PyQt then?

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

      E 1 Reply Last reply 26 Jul 2024, 11:11
      0
      • J jsulm
        26 Jul 2024, 11:07

        Why don't you use PyQt then?

        E Offline
        E Offline
        explorer100
        wrote on 26 Jul 2024, 11:11 last edited by explorer100
        #4

        @jsulm I guess that might be the way to go. Except I have lots of pre-built plots already in matplotlib and seaborn. I was hoping to capitalize on that work.

        I am also using other libraries that generate plots in matplotlib.

        Any recommendations to try?

        J 1 Reply Last reply 26 Jul 2024, 11:40
        0
        • E explorer100
          26 Jul 2024, 11:11

          @jsulm I guess that might be the way to go. Except I have lots of pre-built plots already in matplotlib and seaborn. I was hoping to capitalize on that work.

          I am also using other libraries that generate plots in matplotlib.

          Any recommendations to try?

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 26 Jul 2024, 11:40 last edited by
          #5

          @explorer100 said in Unable to successfully import files with mix use of PySide6 and PyQt6:

          Any recommendations to try?

          Use PyQt to generate code from the ui file.
          You can't mix PySide and PyQt.

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

          E 1 Reply Last reply 26 Jul 2024, 11:59
          1
          • J jsulm
            26 Jul 2024, 11:40

            @explorer100 said in Unable to successfully import files with mix use of PySide6 and PyQt6:

            Any recommendations to try?

            Use PyQt to generate code from the ui file.
            You can't mix PySide and PyQt.

            E Offline
            E Offline
            explorer100
            wrote on 26 Jul 2024, 11:59 last edited by
            #6

            @jsulm Thats great!! didnt know you can do that!!

            E 1 Reply Last reply 26 Jul 2024, 13:30
            0
            • E explorer100
              26 Jul 2024, 11:59

              @jsulm Thats great!! didnt know you can do that!!

              E Offline
              E Offline
              explorer100
              wrote on 26 Jul 2024, 13:30 last edited by explorer100
              #7

              @explorer100 so pyside6 and pyqt6 cannot co-exist?

              J J 2 Replies Last reply 26 Jul 2024, 13:39
              0
              • E explorer100
                26 Jul 2024, 13:30

                @explorer100 so pyside6 and pyqt6 cannot co-exist?

                J Offline
                J Offline
                JonB
                wrote on 26 Jul 2024, 13:39 last edited by
                #8

                @explorer100 No, they are two different implementations of Qt for Python.

                E 1 Reply Last reply 26 Jul 2024, 13:44
                0
                • E explorer100
                  26 Jul 2024, 13:30

                  @explorer100 so pyside6 and pyqt6 cannot co-exist?

                  J Offline
                  J Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 26 Jul 2024, 13:44 last edited by
                  #9

                  @explorer100 said in Unable to successfully import files with mix use of PySide6 and PyQt6:

                  so pyside6 and pyqt6 cannot co-exist?

                  Not in the same application.

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

                  1 Reply Last reply
                  0
                  • J JonB
                    26 Jul 2024, 13:39

                    @explorer100 No, they are two different implementations of Qt for Python.

                    E Offline
                    E Offline
                    explorer100
                    wrote on 26 Jul 2024, 13:44 last edited by explorer100
                    #10

                    @JonB after switching, a number of things are not working the same. I was capturing the accept() to do verifications. after verifying i was issuing self.done(QDialog.Accepted) which used to work well in pyside6. with PyQt6 it just crashes.

                    I guess my question is .. whats a better way to do verifications in a custom dialog with ok, cancel buttons.

                    J 1 Reply Last reply 26 Jul 2024, 13:52
                    0
                    • E explorer100
                      26 Jul 2024, 13:44

                      @JonB after switching, a number of things are not working the same. I was capturing the accept() to do verifications. after verifying i was issuing self.done(QDialog.Accepted) which used to work well in pyside6. with PyQt6 it just crashes.

                      I guess my question is .. whats a better way to do verifications in a custom dialog with ok, cancel buttons.

                      J Offline
                      J Offline
                      JonB
                      wrote on 26 Jul 2024, 13:52 last edited by
                      #11

                      @explorer100
                      I cannot say what the effects of matplot might be. Remove that. UI stuff should work same across PySide or PyQt. No "crashes". So get that working first. If not show simple code.

                      self.done(QDialog.Accepted) (or just self.accept()) should be fine across both. Don't seek to change code at this stage, that might only lead to other issues, find out what your problem is.

                      1 Reply Last reply
                      0
                      • E Offline
                        E Offline
                        explorer100
                        wrote on 26 Jul 2024, 14:53 last edited by explorer100
                        #12
                        This post is deleted!
                        J 1 Reply Last reply 26 Jul 2024, 14:56
                        0
                        • E explorer100
                          26 Jul 2024, 14:53

                          This post is deleted!

                          J Offline
                          J Offline
                          JonB
                          wrote on 26 Jul 2024, 14:56 last edited by JonB
                          #13

                          @explorer100
                          What "tracebacks" and what "verbose"? You have Python debugger, print() statements, and Python lets you print a stack trace if that is what you mean. But debugger is most flexible. What is your "crash", how do you know it has "crashed", what message do you get? Have you run it under Python debugger? If Python itself is "crashing" that is different from your application "crashing".

                          E 1 Reply Last reply 26 Jul 2024, 15:21
                          0
                          • J JonB
                            26 Jul 2024, 14:56

                            @explorer100
                            What "tracebacks" and what "verbose"? You have Python debugger, print() statements, and Python lets you print a stack trace if that is what you mean. But debugger is most flexible. What is your "crash", how do you know it has "crashed", what message do you get? Have you run it under Python debugger? If Python itself is "crashing" that is different from your application "crashing".

                            E Offline
                            E Offline
                            explorer100
                            wrote on 26 Jul 2024, 15:21 last edited by explorer100
                            #14

                            @JonB just the application is crashing..

                            I have a custom dialog that captures the accept and reject
                            on reject i just issue self.done(QDialog.Rejected)

                            the custom dialog is invoked as such:

                            def newFile(self):
                                from PyQt6.QtWidgets import QDialog
                                dialog = NewProjectDialog()
                                ret = dialog.exec()
                                if (ret == QDialog.Accepted):
                                    print("User accepted.")
                                elif ret == QDialog.Rejected:
                                    print("User rejected.")
                                else :
                                    print("unknown return")
                            

                            it actually never returns from the exec()

                            the NewProjectDialog has the below reject() function.

                            def reject(self):
                            
                                from PyQt6.QtWidgets import QDialog
                                print("will do the reject processing here")
                                self.done(QDialog.Rejected)
                            
                            J 1 Reply Last reply 26 Jul 2024, 15:40
                            0
                            • E explorer100
                              26 Jul 2024, 15:21

                              @JonB just the application is crashing..

                              I have a custom dialog that captures the accept and reject
                              on reject i just issue self.done(QDialog.Rejected)

                              the custom dialog is invoked as such:

                              def newFile(self):
                                  from PyQt6.QtWidgets import QDialog
                                  dialog = NewProjectDialog()
                                  ret = dialog.exec()
                                  if (ret == QDialog.Accepted):
                                      print("User accepted.")
                                  elif ret == QDialog.Rejected:
                                      print("User rejected.")
                                  else :
                                      print("unknown return")
                              

                              it actually never returns from the exec()

                              the NewProjectDialog has the below reject() function.

                              def reject(self):
                              
                                  from PyQt6.QtWidgets import QDialog
                                  print("will do the reject processing here")
                                  self.done(QDialog.Rejected)
                              
                              J Offline
                              J Offline
                              JonB
                              wrote on 26 Jul 2024, 15:40 last edited by JonB
                              #15

                              @explorer100 said in Unable to successfully import files with mix use of PySide6 and PyQt6:

                              @JonB just the application is crashing..

                              What does this mean? I asked how you know it is "crashing". If you get neither a message nor some particular behaviour you would not even know it had "crashed"....

                              You do not say whether you even get the message from your reject() or not. So we don't know whether it enters that but does not return from the exec() or whether it never enters the reject() in the first place. Please supply this sort of description with your questions, else we have to cross-examine you at every point because we cannot guess what you are/are not seeing.

                              Replace your custom dialog with a plain QDialog and see if that works. Then subclass QDialog for a custom dialog and just override reject() and see how that goes. Then work up to your actual custom dialog.

                              There is nothing special here. I would just call this standard debugging techniques. I don't know why you are seeing different behaviour between PySide & PyQt, I'm not going to have a magic answer, you have to do some investigation.

                              1 Reply Last reply
                              0
                              • E Offline
                                E Offline
                                explorer100
                                wrote on 26 Jul 2024, 15:54 last edited by explorer100
                                #16

                                sorry, not enough info.
                                it actually enters the reject.
                                with further checks.. if I remove the
                                if (ret == QDialog.Accepted):
                                and simply print ret, it actually prints the correct return!
                                after that.. if I even I try to print out the value of QDialog.Accepted, as in:
                                print("QDialog.Accepted",QDialog.Accepted)
                                the application crashes!
                                the window disappeared then this message is printed on the console
                                Process finished with exit code -1073740791 (0xC0000409)

                                J 1 Reply Last reply 26 Jul 2024, 16:09
                                0
                                • E explorer100
                                  26 Jul 2024, 15:54

                                  sorry, not enough info.
                                  it actually enters the reject.
                                  with further checks.. if I remove the
                                  if (ret == QDialog.Accepted):
                                  and simply print ret, it actually prints the correct return!
                                  after that.. if I even I try to print out the value of QDialog.Accepted, as in:
                                  print("QDialog.Accepted",QDialog.Accepted)
                                  the application crashes!
                                  the window disappeared then this message is printed on the console
                                  Process finished with exit code -1073740791 (0xC0000409)

                                  J Offline
                                  J Offline
                                  JonB
                                  wrote on 26 Jul 2024, 16:09 last edited by JonB
                                  #17

                                  @explorer100
                                  I'm afraid I don't know. To be clear, are you saying you have "crash" behaviour with one of PyQt vs PySide but not the other on same program? Which exact versions of each? Are you quite sure that nowhere do you mix the two now? Have you removed the matplot stuff for now?

                                  I don't think anyone will be able to tell you from what we have so far. You would need a minimal, standalone example if you want others to test. As I said earlier, I think you need to start from a plain QDialog, or one sub-classed but nothing other than reject() inside it, and test behaviour from there. Then gradually add in whatever you have in your real sub-classed code till something goes wrong.

                                  E 2 Replies Last reply 26 Jul 2024, 16:11
                                  0
                                  • J JonB
                                    26 Jul 2024, 16:09

                                    @explorer100
                                    I'm afraid I don't know. To be clear, are you saying you have "crash" behaviour with one of PyQt vs PySide but not the other on same program? Which exact versions of each? Are you quite sure that nowhere do you mix the two now? Have you removed the matplot stuff for now?

                                    I don't think anyone will be able to tell you from what we have so far. You would need a minimal, standalone example if you want others to test. As I said earlier, I think you need to start from a plain QDialog, or one sub-classed but nothing other than reject() inside it, and test behaviour from there. Then gradually add in whatever you have in your real sub-classed code till something goes wrong.

                                    E Offline
                                    E Offline
                                    explorer100
                                    wrote on 26 Jul 2024, 16:11 last edited by
                                    #18

                                    @JonB thanks.. I will do that.

                                    1 Reply Last reply
                                    0
                                    • J JonB
                                      26 Jul 2024, 16:09

                                      @explorer100
                                      I'm afraid I don't know. To be clear, are you saying you have "crash" behaviour with one of PyQt vs PySide but not the other on same program? Which exact versions of each? Are you quite sure that nowhere do you mix the two now? Have you removed the matplot stuff for now?

                                      I don't think anyone will be able to tell you from what we have so far. You would need a minimal, standalone example if you want others to test. As I said earlier, I think you need to start from a plain QDialog, or one sub-classed but nothing other than reject() inside it, and test behaviour from there. Then gradually add in whatever you have in your real sub-classed code till something goes wrong.

                                      E Offline
                                      E Offline
                                      explorer100
                                      wrote on 26 Jul 2024, 16:44 last edited by explorer100
                                      #19

                                      @JonB
                                      wow ... just figured out the issue...
                                      I needed to have the full path of:
                                      QDialog.DialogCode.Accepted
                                      and QDialog.DialogCode.Rejected

                                      rather than just QDialog.Accepted/Rejected.

                                      Is that a difference between the two environments of just a setting?

                                      J 1 Reply Last reply 26 Jul 2024, 19:36
                                      0
                                      • E explorer100
                                        26 Jul 2024, 16:44

                                        @JonB
                                        wow ... just figured out the issue...
                                        I needed to have the full path of:
                                        QDialog.DialogCode.Accepted
                                        and QDialog.DialogCode.Rejected

                                        rather than just QDialog.Accepted/Rejected.

                                        Is that a difference between the two environments of just a setting?

                                        J Offline
                                        J Offline
                                        JonB
                                        wrote on 26 Jul 2024, 19:36 last edited by
                                        #20

                                        @explorer100
                                        For Python at Qt5 all (most) Qt enumeration types were just defined at "the top level", be that Qt or more specialized ones like QDialog. At Qt6 they were moved to lower-level, more specific areas dependent on their usage, like QDialog.DialogCode here, there are many other cases elsewhere in the Qt classes. Any code or examples you may come across which used such types/constants needs changing from 5 to 6. You are not the first person to fall foul of this.

                                        This ought affect PyQt6 and PySide6 equally, I'm not sure if you are finding a difference. Usually you get a runtime error since the old symbol is not defined. I don't know about your case. You were "unlucky" to come across this issue so early in your attempts. If you have old code or examples look out for such enumerations which need upgrading.

                                        E 1 Reply Last reply 26 Jul 2024, 19:47
                                        0
                                        • J JonB
                                          26 Jul 2024, 19:36

                                          @explorer100
                                          For Python at Qt5 all (most) Qt enumeration types were just defined at "the top level", be that Qt or more specialized ones like QDialog. At Qt6 they were moved to lower-level, more specific areas dependent on their usage, like QDialog.DialogCode here, there are many other cases elsewhere in the Qt classes. Any code or examples you may come across which used such types/constants needs changing from 5 to 6. You are not the first person to fall foul of this.

                                          This ought affect PyQt6 and PySide6 equally, I'm not sure if you are finding a difference. Usually you get a runtime error since the old symbol is not defined. I don't know about your case. You were "unlucky" to come across this issue so early in your attempts. If you have old code or examples look out for such enumerations which need upgrading.

                                          E Offline
                                          E Offline
                                          explorer100
                                          wrote on 26 Jul 2024, 19:47 last edited by
                                          #21

                                          @JonB Thanks Jon for the clarification.
                                          For me, using PySide6.. the enumeration was ok while specifying the top level. I should have made another connection with a previous issue where I couldn't specify Qmessage.Information anymore. After discovering this, I changed it to QMessageBox.Icon.Information and all is well.

                                          Thanks again for your support.

                                          By the way.. the matplotlib interface now also looks like it might work with all using PyQt6.
                                          will keep you posted. thanks again.

                                          J 1 Reply Last reply 26 Jul 2024, 19:56
                                          0

                                          11/22

                                          26 Jul 2024, 13:52

                                          • Login

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