It is always risky to upgrade your operation system. It is likely you will encounter some compatibility issue. I took the risk to upgrade my macOS from Catalina to the newest Big Sur. After that, the display in the new OS looks pretty, but all my PyQt5 apps could not be launched in this new OS. The GUI window does not pop up as usual, and there is no error message showing in the terminal. I spent the whole day trying to figure out what makes this problem. I found the solution but in a weird way which I feel confused.
It turns out that the apps comes back to normal after I add the following three lines in the main script.
import matplotlib
import matplotlib.pyplot as plt
matplotlib.use('TkAgg')
It seems to me the new OS has some compatibility issue with Qt5Agg back-end. But the strange thing is that this solution also works for one of the Pyqt5 app, where I don't use matplotlib at all.
The Python version I used is 3.8.4, and the PyQt5 version I have is 5.15.1.
I hope somebody could explain to me what happen under the hood that makes this solution work. Also I hope this temporary solution can help somebody with the same problem.
Internet connectivity issues or Apple’s server issues could likely be a reason for this error as well. To fix this, you can start your Mac in safe mode by holding the Shift key while your system boots and then try to download/install macOS Big Sur again.
macOS Big Sur 11.0.1 enables you to test your iPad and iPhone apps through Xcode. Below are notes pertaining to running these apps on macOS Big Sur 11.0.1. For additional macOS 11 changes, see macOS Big Sur 11.0.1 Release Notes.
Some of the apps installed on your Mac may behave abnormally or crash upon launching after updating to macOS Big Sur. This is likely because the apps haven’t been updated to support the latest version of system software yet.
This is a pretty common issue after every major macOS update, but there’s nothing to worry about in most cases. After successfully installing the update, if macOS Big Sur notified you with a message saying “Optimizing Your Mac: Performance and battery life may be affected until completed”, then it’s nothing out of the ordinary.
I can confirm that matplotlib.use('TkAgg')
followed by matplotlib.use('Qt5Agg')
makes things work for me, too. I whittled it down to this as also working:
# from matplotlib.backends import _tkagg
import _tkinter
import matplotlib.pyplot as plt
plt.figure()
So it's something about the compiled _tkinter
module. Maybe the inputhook?
I followed the solution here and downgraded to PyQt 5.13. This solved my issue and allowed my compiled apps to run on Big Sur.
pip install PyQt5==5.13
As @Eric said, just add the following on the very start of your code, before the PySide2 import:
import os
os.environ["QT_MAC_WANTS_LAYER"] = "1"
Then import PyQt5/PySide2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With