2

I have been writing a PyQt Application on Windows for awhile, and I wanted to see if it would run properly on Linux. The gui application is basically a shell for a scientific toolkit meant to be used on the qtconsole/notebook. Both Linux and Windows systems are based on Anaconda 3.5, and running PyQt5. It works fine on Windows, but when I run on Linux, the Qt window pops up bit simply freezes in place the graphics that were underneath the window (see image below). There are no errors at all shown on the command line, the window just pops up and doesn't show widgets at all. Furthermore, when I try to close with the x-button in the top of the window, it shows an "Application not responsive" dialog and I have to force-quite.

The code-base is quite large (too large for this post) so I wouldn't really be able to put in a code example for this problem (I haven't been able to reproduce the error yet outside of this program). I can say that I did get some examples from this site working for simple gui programs: https://github.com/Deusdies/pythonbo . My code has a a lot of widget subclassing, uses pyqtgraph (most recent version from github) for plots, and has a lot of MDI subwindows.

Other packages for the underlying toolkit include:

  • numpy, numba, scipy, matplotlib
  • lmfit
  • pyexcel, pyexcel-xlsx
  • pyvisa, pyserial
  • pyperclip

When I try to run any of the MDI subwindow widgets as individual programs, I get the same problem as running the main program.

I guess I'm curious if anyone has run into this situation before and can suggest likely things I should probe to see what the problem might be.

Frozen PyQt Application

4

1 回答 1

2

The general answer turned out to be that 2 QApplication event loops were being initialized.

The problem code turned out to be in a little module I have been using called pyperclip which was being imported first, and then I was instantiating my QApplication at the bottom of my gui code.

This was not a problem on Windows because pyperclip can access the Windows clipboard somewhat natively, but on Linux it uses the QtClipboard. My solution was to edit the pyperclip code to detect if an application was already running, and then to instantiate my gui application before importing pyperclip

EDIT FOR CODE

in the pyperclip code, pyperclip.clipboards module, line 51 I changed this line:

app = QApplication([])

to this:

app = QApplication.instance()
if app is None:
    app = QApplication([])
于 2016-07-04T20:02:53.077 回答