2

我在 Raspberry Pi 4 上运行 PyQt5 时遇到问题。

我使用树莓派 4,版本 10(buster)内核版本 4.19.75-v71。

默认python是3.7.3。

我按照这里线程中提到的安装 sip 和 PyQt5 的完全相同的步骤进行操作。我还按照上述线程中介绍的步骤安装了 python 3.6.0。

在没有任何错误完成安装后,当我运行我的代码时,我遇到以下错误消息:

qt5ct: using qt5ct plugin

QEGLPlatformContext: Failed to create context: 3009

QOpenGLWindow::beginPaint: Failed to create context

QOpenGLWindow::beginPaint: Failed to make context current

Traceback (most recent call last):

  File "my_code.py", line 68, in initializeGL

    self.gl = self.context().versionFunctions()

AttributeError: module 'PyQt5._QOpenGLFunctions_ES2' has no attribute 'QOpenGLFunctions_ES2'

Aborted

任何指导如何克服这个问题?非常感激。提前致谢。

PS代码在Win10上运行流畅。因此,代码本身一定没有问题。(Win10上的环境为:numpy=1.14.3;numpy-stl=2.5.0;pyqt5=5.10.1;sip=4.19.8;六=1.11.0;python=3.6.0;python-utils=2.3 .0)

4

1 回答 1

0

也许你可以尝试重新安装 pyqt5 来解决这个问题。看看是否有线程占用 pip/pyqt5/qmake.exe。或者看你的GPU,是OpenGL2.0还是更高版本?

你说问题是由“self.gl=self.context().versionFunctions()”造成的,我正在写一个例子,你可以试试:



    import sys
    import math
    from PyQt5.QtCore import pyqtSignal, QPoint, QSize, Qt
    from PyQt5.QtGui import QColor
    from PyQt5.QtWidgets import (QApplication, QHBoxLayout, QOpenGLWidget, QSlider,
                                 QWidget)
    
    import OpenGL.GL as gl
    
    
    class Window(QWidget):
    
        def __init__(self):
            super(Window, self).__init__()
    
            self.glWidget = GLWidget()
    
            self.xSlider = self.createSlider()
            self.ySlider = self.createSlider()
            self.zSlider = self.createSlider()
    
            self.xSlider.valueChanged.connect(self.glWidget.setXRotation)
            self.glWidget.xRotationChanged.connect(self.xSlider.setValue)
            self.ySlider.valueChanged.connect(self.glWidget.setYRotation)
            self.glWidget.yRotationChanged.connect(self.ySlider.setValue)
            self.zSlider.valueChanged.connect(self.glWidget.setZRotation)
            self.glWidget.zRotationChanged.connect(self.zSlider.setValue)
    
            mainLayout = QHBoxLayout()
            mainLayout.addWidget(self.glWidget)
            mainLayout.addWidget(self.xSlider)
            mainLayout.addWidget(self.ySlider)
            mainLayout.addWidget(self.zSlider)
            self.setLayout(mainLayout)
    
            self.xSlider.setValue(15 * 16)
            self.ySlider.setValue(345 * 16)
            self.zSlider.setValue(0 * 16)
    
            self.setWindowTitle("Hello GL")
    
        def createSlider(self):
            slider = QSlider(Qt.Vertical)
    
            slider.setRange(0, 360 * 16)
            slider.setSingleStep(16)
            slider.setPageStep(15 * 16)
            slider.setTickInterval(15 * 16)
            slider.setTickPosition(QSlider.TicksRight)
    
            return slider
    
    
    class GLWidget(QOpenGLWidget):
        xRotationChanged = pyqtSignal(int)
        yRotationChanged = pyqtSignal(int)
        zRotationChanged = pyqtSignal(int)
    
        def __init__(self, parent=None):
            super(GLWidget, self).__init__(parent)
    
            self.object = 0
            self.xRot = 0
            self.yRot = 0
            self.zRot = 0
    
            self.lastPos = QPoint()
    
            self.trolltechGreen = QColor.fromCmykF(0.40, 0.0, 1.0, 0.0)
            self.trolltechPurple = QColor.fromCmykF(0.39, 0.39, 0.0, 0.0)
    
        def getOpenglInfo(self):
            info = """
                Vendor: {0}
                Renderer: {1}
                OpenGL Version: {2}
                Shader Version: {3}
            """.format(
                gl.glGetString(gl.GL_VENDOR),
                gl.glGetString(gl.GL_RENDERER),
                gl.glGetString(gl.GL_VERSION),
                gl.glGetString(gl.GL_SHADING_LANGUAGE_VERSION)
            )
    
            return info
    
        def minimumSizeHint(self):
            return QSize(50, 50)
    
        def sizeHint(self):
            return QSize(400, 400)
    
        def setXRotation(self, angle):
            angle = self.normalizeAngle(angle)
            if angle != self.xRot:
                self.xRot = angle
                self.xRotationChanged.emit(angle)
                self.update()
    
        def setYRotation(self, angle):
            angle = self.normalizeAngle(angle)
            if angle != self.yRot:
                self.yRot = angle
                self.yRotationChanged.emit(angle)
                self.update()
    
        def setZRotation(self, angle):
            angle = self.normalizeAngle(angle)
            if angle != self.zRot:
                self.zRot = angle
                self.zRotationChanged.emit(angle)
                self.update()
    
        def initializeGL(self):
            print(self.getOpenglInfo())
    
            self.setClearColor(self.trolltechPurple.darker())
            self.object = self.makeObject()
            gl.glShadeModel(gl.GL_FLAT)
            gl.glEnable(gl.GL_DEPTH_TEST)
            gl.glEnable(gl.GL_CULL_FACE)
    
        def paintGL(self):
            gl.glClear(
                gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
            gl.glLoadIdentity()
            gl.glTranslated(0.0, 0.0, -10.0)
            gl.glRotated(self.xRot / 16.0, 1.0, 0.0, 0.0)
            gl.glRotated(self.yRot / 16.0, 0.0, 1.0, 0.0)
            gl.glRotated(self.zRot / 16.0, 0.0, 0.0, 1.0)
            gl.glCallList(self.object)
    
        def resizeGL(self, width, height):
            side = min(width, height)
            if side  360 * 16:
                angle -= 360 * 16
            return angle
    
        def setClearColor(self, c):
            gl.glClearColor(c.redF(), c.greenF(), c.blueF(), c.alphaF())
    
        def setColor(self, c):
            gl.glColor4f(c.redF(), c.greenF(), c.blueF(), c.alphaF())
    
    
    if __name__ == '__main__':
    
        app = QApplication(sys.argv)
        window = Window()
        window.show()
        sys.exit(app.exec_())


在尝试这个例子之前,请运行这个命令(安装 pyOpenGL): pip install pyOpenGL

于 2021-07-10T07:26:54.763 回答