python - 致命的 Python 错误:PyQt5.QtCore:无法嵌入 qt.conf
问题描述
我一直在使用 PyQt5 创建一个 GUI 应用程序。这个应用程序在几周前可以完美运行,但现在它显示了一个致命错误。我认为它无法导入 qt.core。我什至尝试创建一些基本应用程序,但仍然会发生此错误。
下面是应用程序的代码:
import sys
from PyQt5.QtWidgets import QMainWindow, QApplication, QPushButton, QWidget, QAction, QTabWidget,QVBoxLayout,QLabel
#Creating the main window
class App(QMainWindow):
def __init__(self):
super().__init__()
self.title = 'PyQt5 - QTabWidget'
self.left = 0
self.top = 0
self.width = 300
self.height = 200
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
self.tab_widget = MyTabWidget(self)
self.setCentralWidget(self.tab_widget)
self.show()
#Creating tab widgets
class MyTabWidget(QWidget):
def __init__(self, parent):
super(QWidget, self).__init__(parent)
self.layout = QVBoxLayout(self)
#Initialize tab screen
self.tabs = QTabWidget()
self.tab1 = QWidget()
self.tab2 = QWidget()
self.tab3 = QWidget()
self.tabs.resize(300,200)
#Add tabs
self.tabs.addTab(self.tab1,"Tab1")
self.tabs.addTab(self.tab2,"Tab2")
self.tabs.addTab(self.tab3,"Tab3")
#Create first tab
self.tab1.layout = QVBoxLayout(self)
self.l = QLabel()
self.l.setText("This is the first tab")
self.tab1.layout.addWidget(self.l)
self.tab1.setLayout(self.tab1.layout)
#Add tabs to widget
self.layout.addWidget(self.tabs)
self.setLayout(self.layout)
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())
这不是我的应用程序,它是一个基本的 GUI,它显示相同的错误。 它显示的错误如下:
Fatal Python error: PyQt5.QtCore: Unable to embed qt.conf
AttributeError: module 'PyQt5' has no attribute '__file__'
Current thread 0x0000000119c675c0 (most recent call first):
File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
File "<frozen importlib._bootstrap_external>", line 922 in create_module
File "<frozen importlib._bootstrap>", line 571 in module_from_spec
File "<frozen importlib._bootstrap>", line 658 in _load_unlocked
File "<frozen importlib._bootstrap>", line 955 in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 971 in _find_and_load
File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
File "<frozen importlib._bootstrap_external>", line 922 in create_module
File "<frozen importlib._bootstrap>", line 571 in module_from_spec
File "<frozen importlib._bootstrap>", line 658 in _load_unlocked
File "<frozen importlib._bootstrap>", line 955 in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 971 in _find_and_load
File "/Users/mac/Desktop/major/temp.py", line 2 in <module>
解决方案
我运行了这个程序,它可以工作。如果您使用 python 2 或旧的 pyqt 版本,则可能会出现此错误。看来你应该更新了。如果不是这样,请告诉我
推荐阅读
- java - spark与kafka的整合,Spark中的异常——提交一个jar
- regex - 正则表达式不应与所有可能的特定单词匹配
- python - py 调用返回的大小大于分辨率
- javascript - 从众多输入之一中获得最高价值
- android - 是否可以在返回 LiveData 的 Room @DAO 中编写“挂起”函数?
- android - 如何在 xml 中编辑最上面导航栏的颜色?
- python-3.x - 检查点文件的加载方式/位置
- c++ - QQmlEngine retranslate not translating other StackView items
- apache-spark - 不支持重新分区后合并
- java - 片段中的自定义ListView,我需要什么文件?