pythonopenglvisual-c++pyopenglvisual-studio-2017-build-tools

PyOpenGL :: OpenGL.error.NullFunctionError: Attempt to call an undefined function glutInit, check for bool(glutInit) before calling


I'm following this very easy guide in order to make my first steps into PyOpenGL.

  1. I installed pip install PyOpenGL PyOpenGL_accelerate , all good.

  2. I tested the installation through the test code:

    import OpenGL.GL import OpenGL.GLUT import OpenGL.GLU print("Imports successful!") # If you see this printed to the console then installation was successful

all good

I now run this script:

from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *

w,h= 500,500
def square():
    glBegin(GL_QUADS)
    glVertex2f(100, 100)
    glVertex2f(200, 100)
    glVertex2f(200, 200)
    glVertex2f(100, 200)
    glEnd()

def iterate():
    glViewport(0, 0, 500, 500)
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    glOrtho(0.0, 500, 0.0, 500, 0.0, 1.0)
    glMatrixMode (GL_MODELVIEW)
    glLoadIdentity()

def showScreen():
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    glLoadIdentity()
    iterate()
    glColor3f(1.0, 0.0, 3.0)
    square()
    glutSwapBuffers()

glutInit()
glutInitDisplayMode(GLUT_RGBA)
glutInitWindowSize(500, 500)
glutInitWindowPosition(0, 0)
wind = glutCreateWindow("OpenGL Coding Practice")
glutDisplayFunc(showScreen)
glutIdleFunc(showScreen)
glutMainLoop()

And the error I receive is OpenGL.error.NullFunctionError: Attempt to call an undefined function glutInit, check for bool(glutInit) before calling

So i read a few guides online and they point to download the wheel from here. So I go ahead and I download PyOpenGL_accelerate‑3.1.5‑cp38‑cp38‑win_amd64.whl and PyOpenGL‑3.1.5‑cp38‑cp38‑win_amd64.whl because I'm running Python 3.8

  1. pip install .\PyOpenGL_accelerate-3.1.5-cp39-cp39-win_amd64.whl returns PyOpenGL-accelerate is already installed with the same version as the provided wheel. Use --force-reinstall to force an installation of the wheel.
  2. pip install .\PyOpenGL_accelerate-3.1.5-cp38-cp38-win_amd64.whl returns PyOpenGL-accelerate is already installed with the same version as the provided wheel. Use --force-reinstall to force an installation of the wheel.

How can a so simple guide lead me to a so painful result?

How can I check if Visual C++ 14.0 build tools is installed. Maybe that is the only step I'm missing?


Solution

  • Since "Unofficial Windows Binaries for Python Extension Packages" no longer exist (see Christoph Gohlke's Windows Wheels site is shutting down by the end of the month), the following solution no longer works:

    The _freeglut_ DLL is missing from the package.

    Unistall "PyOpenGL":

    pip uninstall pyopengl
    

    Download the package wheel (e.g.: "PyOpenGL‑3.1.6‑cp311‑cp311‑win_amd64.whl") from, Unofficial Windows Binaries for Python Extension Packages and install it:

    pip install PyOpenGL‑3.1.6‑cp311‑cp311‑win_amd64.whl
    

    Alternatively the wheels may be found here: https://drive.google.com/drive/folders/1mz7faVsrp0e6IKCQh8MyZh-BcCqEGPwx


    If you don't find a wheel for your needs, you need to clone the mcfletch/pyopengl repository and install PyOpenGL from the repository (see also PyOpenGL and PyOpenGL_Accelerate):

    clone the repository:

    git clone https://github.com/mcfletch/pyopengl
    

    install pyopengl and pyopengl_accelerate:

    cd pyopengl
    pip install -e .
    cd accelerate
    pip install -e .