問(wèn)題描述
升級(jí)操作系統(tǒng)總是有風(fēng)險(xiǎn)的.您可能會(huì)遇到一些兼容性問(wèn)題.我冒險(xiǎn)將我的 macOS 從 Catalina 升級(jí)到最新的 Big Sur.在那之后,新操作系統(tǒng)中的顯示看起來(lái)很漂亮,但是我所有的 PyQt5 應(yīng)用程序都無(wú)法在這個(gè)新操作系統(tǒng)中啟動(dòng).GUI 窗口沒(méi)有像往常一樣彈出,并且終端中沒(méi)有顯示錯(cuò)誤消息.我花了一整天的時(shí)間試圖弄清楚是什么導(dǎo)致了這個(gè)問(wèn)題.我找到了解決方案,但以一種奇怪的方式讓我感到困惑.
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.
我在主腳本中添加以下三行后,應(yīng)用程序恢復(fù)正常.
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')
在我看來(lái),新操作系統(tǒng)與 Qt5Agg 后端存在一些兼容性問(wèn)題.但奇怪的是,這個(gè)解決方案也適用于其中一個(gè) Pyqt5 應(yīng)用程序,我根本不使用 matplotlib.
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.
我使用的Python版本是3.8.4,我的PyQt5版本是5.15.1.
The Python version I used is 3.8.4, and the PyQt5 version I have is 5.15.1.
我希望有人可以向我解釋使該解決方案起作用的幕后情況.我也希望這個(gè)臨時(shí)解決方案可以幫助有同樣問(wèn)題的人.
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.
推薦答案
回復(fù) PyQt 郵件列表指出設(shè)置這個(gè) env var 有效:
A reply to the PyQt mailing list pointed out that setting this env var works:
QT_MAC_WANTS_LAYER=1
通過(guò) 是否有任何關(guān)于 PyQt 庫(kù)在 Mac OS Big Sur 中不起作用的解決方案? 和 https://forums.macrumors.com/threads/pyqt5-and-big-sur.2260773/?post=29243620#post-29243620
這篇關(guān)于macOS Big Sur 11.0.1 上未彈出應(yīng)用程序的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!