致命的Python错误:PyQt5.QtCore:无法嵌入qt.conf

问题描述 投票:0回答:1

我一直在使用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 python-3.x user-interface pyqt pyqt5
1个回答
0
投票

我运行了该程序,它可以正常工作。如果您使用的是python 2或旧的pyqt版本,则可能出现此错误。看来您应该进行更新。如果不是这样,请告诉我]

© www.soinside.com 2019 - 2024. All rights reserved.