12

I need a glut window in python. I have the following exception using Python 3.5 and PyOpenGL.GLUT

Traceback (most recent call last):
  File "D:\...\Test.py", line 47, in <module>

    if __name__ == '__main__': main()
  File "D:\...\Test.py", line 9, in main
    glutInit(sys.argv)
  File "C:\...\OpenGL\GLUT\special.py", line 333, in glutInit
    _base_glutInit( ctypes.byref(count), holder )
  File "C:\...\OpenGL\platform\baseplatform.py", line 407, in __call__
    self.__name__, self.__name__,

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

Platform: Windows

Why do i get this error?

Here is my code:

from OpenGL.GLUT import *
import sys

glutInit(sys.argv)
3
  • Possible duplicate: stackoverflow.com/questions/26700719/…
    – ash
    Aug 27, 2016 at 12:36
  • that question has no answer marked as solution, and the real problem is that the module is not properly reporting missing dll files Aug 27, 2016 at 12:39
  • and that question is about anaconda and python 2.7 Aug 27, 2016 at 12:40

2 Answers 2

14

Problems:

  • There was no problem with pip install or easy_install
  • The glut.dll and glut32.dll were missing. (They are not part of the PyPI package) you have to install them separately or download it like I did.

Unzipped the dll files from the glutdlls.zip and placed them next to my python file.

Note: You can add the dll files to your PATH variable. Not necessary to keep them next to the py file.

8
  • 3
    Worked for me.Some clarification for future readers of this: The link to the two needed dlls is: link On Windows 7 put glut.dll and glut32.dll in your Python2.7 OpenGL DLL folder.
    – JayJay123
    Feb 25, 2017 at 8:25
  • 4
    The FTP link is no longer hosted. Jul 5, 2019 at 22:08
  • 7
    Uninstall your current PyOpenGL and simply download PyOpenGL from Unofficial Windows Python Binaries and then install the whl using pip.
    – MAY
    Jan 4, 2020 at 14:35
  • 1
    As @KareemElashmawy indicated, the link of @JayJay is not available anymore. From: transmissionzero.co.uk/files/software/development/GLUT/… one can copy the /freeglut-MSVC-3.0.0-2.mp\freeglut\bin\x64/freeglut.dll file into the folder of the .py script you are trying to run. This resolves the error from OpenGL.error.NullFunctionError: Attempt to call an undefined function glutInit to: ctypes.ArgumentError: wrong type at OpenGL\GLUT\special.py", line 73, in glutCreateWindow. Perhaps cause I only found 1/2 .dll files.
    – a.t.
    Aug 12, 2020 at 10:53
  • 2
    The 2nd error was for installing "official" PyOpenGL with: conda install -c conda-forge pyopengl which didnt work. Solution I uninstalled the official version with pip uninstall PyOpenGL and installed the Unofficial Windows Binaries as @MAY suggested. That initially threw errors: .whl is not a supported wheel on this platform. for both the 32 and 64 bit version, but that was because I forgot to select the python 36 version with the name PyOpenGL‑3.1.5‑cp<PYTHON VERSION>‑cp<PYTHON VERSION>m‑win_amd64.whl. Hope this helps someone. Also installed conda install -c conda-forge freeglut.
    – a.t.
    Aug 12, 2020 at 12:37
1

I was being thrown the same error message. I tried installing the DLLs separately and everything and nothing worked. The code that gave me the error was calling the glutInit() function. While I was getting the error, my imports looked like:

import OpenGL
import OpenGL.GL
import OpenGL.GLUT
import OpenGL.GLU

I then changed my imports to:

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

and the error was fixed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.