[PyQt] QOpenGLWidget missing module PyQt5._QOpenGLFunctions_2_1

Erik Hvatum ice.rikh at gmail.com
Fri Mar 13 00:25:57 GMT 2015

On Thu, Mar 12, 2015 at 7:23 PM, Erik Hvatum <ice.rikh at gmail.com> wrote:

> On Wed, Mar 11, 2015 at 5:45 PM, Phil Thompson <
> phil at riverbankcomputing.com> wrote:
>> On 11/03/2015 9:30 pm, Peter Jensen wrote:
>>> Hi
>>> I have a problem using the QOpenGLWidget.
>>> I get an import error concerning missing module:
>>> PyQt5._QOpenGLFunctions_2_1
>>> Among many other things, I have tried forcing OpenGL 2.0 with
>>> QSurfaceFormat() and setVersion, but it doesn’t appear to make any
>>> difference.
>> If you mean that it still tries to import _QOpenGLFunctions_2_1 then you
>> haven't managed to tell it to use OpenGL 2.0.
>>  Using Windows 8.1, Python 3.4.2(x32) and
>>> PyQt5-5.4.1-gpl-Py3.4-Qt5.4.1-x32
>>> Running the included example hellogl.py results in:
>>> File "C:/Python34/Lib/site-packages/PyQt5/examples/opengl/hellogl.py",
>>> line
>>> 142, in initializeGL
>>>     self.gl = self.context().versionFunctions()
>>> ImportError: No module named 'PyQt5._QOpenGLFunctions_2_1'
>>> Hellogl.py based on QGLWidget in PyQT 5.4.0 examples works.
>>> Any help that would make QOpenGLWidget work, is very welcome.
>> I'm still discovering what's needed to make things work on all machines.
>> I'll add the 2.1 module in the next installer.
>> Phil
Of course, it is possible to request a lesser version functions ball.
Here's what I do (feel free to copy/paste):

 def GL():    global _GL    if _GL is None:        context =
Qt.QOpenGLContext.currentContext()        if context is not None:
      try:                _GL = context.versionFunctions()
except ImportError:                # PyQt5 v5.4.0 and v5.4.1 provide
access to OpenGL functions up to OpenGL 2.0, but we have made
      # an OpenGL 2.1 context.  QOpenGLContext.versionFunctions(..)
will, by default, attempt to return                # a wrapper around
QOpenGLFunctions2_1, which has failed in the try block above.
Therefore,                # we fall back to explicitly requesting 2.0
functions.  We don't need any of the C _GL 2.1                #
constants or calls, anyway - these address non-square shader uniform
transformation matrices and                # specification of sRGB
texture formats, neither of which we use.                vp =
vp.setVersion(2, 0)                _GL = context.versionFunctions(vp)
          if not _GL:                raise RuntimeError('Failed to
retrieve OpenGL wrapper namespace.')            if not
_GL.initializeOpenGLFunctions():                raise
RuntimeError('Failed to initialize OpenGL wrapper namespace.')
return _GL

FYI, the _GL.initializeOpenGLFunctions() call is unnecessary, but my OCD
demands it.


PS: apologies to Phil for sending this reply directly to his email address
and not the list the first time around...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150312/93fab1c2/attachment.html>

More information about the PyQt mailing list