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)
Szabolcs Dombi
  • 5,493
  • 3
  • 39
  • 71

2 Answers2

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.

Szabolcs Dombi
  • 5,493
  • 3
  • 39
  • 71
  • 3
    Worked for me.Some clarification for future readers of this: The link to the two needed dlls is: [link](ftp://ftp.sgi.com/opengl/glut/glutdlls.zip) On Windows 7 put `glut.dll` and `glut32.dll` in your Python2.7 OpenGL DLL folder. – JayJay123 Feb 25 '17 at 08:25
  • The FTP link is no longer hosted. – KareemElashmawy Jul 05 '19 at 22:08
  • 4
    The FTP link is no longer hosted. – KareemElashmawy Jul 05 '19 at 22:08
  • 7
    Uninstall your current PyOpenGL and simply download PyOpenGL from [Unofficial Windows Python Binaries](https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopengl) and then install the whl using pip. – MAY Jan 04 '20 at 14:35
  • 1
    As @KareemElashmawy indicated, the link of @JayJay is not available anymore. From: https://www.transmissionzero.co.uk/files/software/development/GLUT/freeglut-MSVC.zip 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 '20 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‑cpm‑win_amd64.whl`. Hope this helps someone. Also installed `conda install -c conda-forge freeglut`. – a.t. Aug 12 '20 at 12:37
  • Had to deal with this recently, @MAY's recommendation is what worked for me. installing freeglut from conda-forge was not required in my case, maybe because I already had it somewhere else (vcpkg?) – HUSMEN Oct 13 '21 at 07:11
  • I had to name the glut dll as "site-packages/OpenGL/DLLS/freeglut64.vc9.dll" before it was found. Finding the dll is the job of "OpenGL/platform/ctypesloader.py" and I had to breakpoint inside that file to find out what file name it was seeking. (Am using python 2.7) – Paul Van Camp Feb 13 '22 at 09:04
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.

Jay Seiner
  • 11
  • 1