【问题标题】:Fatal Python error: PyQt5.QtCore: Unable to embed qt.conf致命的 Python 错误:PyQt5.QtCore:无法嵌入 qt.conf
【发布时间】:2020-07-24 20:11:13
【问题描述】:

我一直在使用 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>

【问题讨论】:

  • 我遇到了这个问题。卸载并重新安装 PyQt5 和 PyQt3D 为我修复了它:pip3 uninstall PyQt5 PyQt3D ; pip3 install -U PyQt3D PyQt5

标签: python python-3.x user-interface pyqt pyqt5


【解决方案1】:

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

【讨论】:

  • 谢谢,但我已经在使用 python 3 和 pyqt5。它仍然无法正常工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-10
  • 2022-01-25
  • 2014-07-05
相关资源
最近更新 更多