Problem with 'glutinit()'

The function ‘glutinit()’ cannot be completed. It raises the following error:
OpenGL.error.NullFunctionError: Attempt to call an undefined function glutInit, check for bool(glutInit) before calling

Example code:

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

# defining the coordinates
w, h = 500,500

# function to create square
def square():
    glBegin(GL_QUADS) # Begin the sketch
    glVertex2f(100, 100) # Coordinates for the bottom left point
    glVertex2f(200, 100) # Coordinates for the bottom right point
    glVertex2f(200, 200) # Coordinates for the top right point
    glVertex2f(100, 200) # Coordinates for the top left point
    glEnd() # Mark the end of drawing

# Initialize the window and display the square
def showScreen():
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # Remove everything from screen (i.e. displays all white)
    glLoadIdentity() # Reset all graphic/shape's position
    square() # Draw a square using our function
    glutSwapBuffers()

glutInit() # *This raises an error - See at the end*
glutInitDisplayMode(GLUT_RGBA) # Set the display mode to be colored
glutInitWindowSize(500, 500)   # Set the w and h of your window
glutInitWindowPosition(0, 0)   # Set the position at which this windows should appear
wind = glutCreateWindow("OpenGL Coding Practice") # Set a window title
glutDisplayFunc(showScreen)
glutIdleFunc(showScreen) # Keeps the window open
glutMainLoop()  # Keeps the above created window displaying/running in a loop

(End of code)

Traceback of the error produced by ‘glutinit’:
File “G:\Python3.12\Lib\site-packages\OpenGL\GLUT\special.py”, line 333, in glutInit
** _base_glutInit( ctypes.byref(count), holder )**
** File “G:\Python3.12\Lib\site-packages\OpenGL\platform\baseplatform.py”, line 423, in call**
** raise error.NullFunctionError(**
OpenGL.error.NullFunctionError: Attempt to call an undefined function glutInit, check for bool(glutInit) before calling

This is an issue with the PyOpenGL installation. Try asking on a Python forum (PyOpenGL has a mailing list, but it hasn’t had a post since 2021). Be sure to detail exactly which packages (Python, PyOpenGL) you’re using.

Ensure that the version of PyOpenGL is compatible with the version of Python. Also check whether you have any other versions of the GLUT DLL installed. I suspect that GLUT fails to load but it’s not reporting the error.

I thank you for your reply. From politeness. Because all this is too general and does not help at. It is clear that you have no idea about this problem which is a very common problem in GitHub, stackoverflow, etc.
More specifically, you say:

  1. “This is an issue with the PyOpenGL installation.”
    There’s nothing wrong with my PyOpenGL installation. I have tested a lot of OpenGL examples w/o problem.
  2. “Try asking on a Python forum (PyOpenGL has a mailing list …”
    I have not asked GitHub and stackoverflow, because the problem is already posted in them and the very few “solutions”, which I tried didn’t work.
  3. “Ensure that the version of PyOpenGL is compatible with the version of Python.”
    If PyOpenGL was not compatible with the version of my Python (3.12) my problem would be much differenent.

Oh, come on. I would have appreciated more if you had said “I have no idea about the problem neither do I know anywone who can answer it.” Or even if you didn’t reply at all …

glutInit is the very first call in your program. If it fails, it can’t be because of anything else your program has done because your program hasn’t done anything else at that point.

NullFunctionError usually occurs when you call an OpenGL function which was added in a later version of OpenGL than the one that’s installed on your system. The only way it can occur for glutInit is if the GLUT DLL failed to load. Which is fundamentally an installation issue: either PyOpenGL wasn’t installed correctly or it is incompatible with your system in some way (wrong Windows version, wrong Python version, or there are existing DLLs which are interfering with it).

In any case: this isn’t an OpenGL question, it doesn’t belong on this forum, and if anyone is capable of answering it you’re more likely to find them on a Python forum than here.

Thank you for your response.
Yes, all this make sense. In fact I suspected it was a version conflict problem. Among quite a few OpenGL similar cases. In fact, I have had enough of all this and stopped working with OpenGL after a few days.
As for the particular problem, I debugged it and found that it had to do with some kind of “extensions”. Too complicated stuff and I was not willing to take my guts out resolving it. I even created a DLLs folder and put in there the 64-bit freeglut dlls I downloaded which I also stored in the current path I was running an OpenGL Python script. Nothing. It was one of these cases that the problem has a sould that does not wish to be resolved! :grinning:
So, the best thing to do in such cases, I mean with such problematic packages as OpenGL (maybe the most problematic I’ve ever met) is to stop wasting time and effort and forget about the whole package.

Re “this isn’t an OpenGL question, it doesn’t belong on this forum”:
Well, I have been led here after a suggestion from some Python forum. :slightly_smiling_face:
It’s a very common problem, and yet I have not found any solution anywhere.
So, as I said, bye, bye OpenGL, there’s other fish to fry …

I would advise you to find a good Python+OpenGL tutorial. Any learning material that’s teaching you outdated functions like glVertex and the like is not worth using.