Attempt to call an undefined function glutInit
Asked Answered
S

3

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)
Spittoon answered 27/8, 2016 at 12:34 Comment(3)
Possible duplicate: #26701219Expediency
that question has no answer marked as solution, and the real problem is that the module is not properly reporting missing dll filesSpittoon
and that question is about anaconda and python 2.7Spittoon
S
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.

Spittoon answered 27/8, 2016 at 12:34 Comment(8)
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.Fairspoken
The FTP link is no longer hosted.Comprador
The FTP link is no longer hosted.Comprador
Uninstall your current PyOpenGL and simply download PyOpenGL from Unofficial Windows Python Binaries and then install the whl using pip.Corselet
As @Comprador 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.Vedda
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 @Corselet 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.Vedda
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?)Casiano
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)Russi
V
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.

Vaucluse answered 5/8, 2022 at 17:8 Comment(1)
But this is what the OP did. I also did that and the error cries out loud!Brittneybrittni
S
0

I tried some other thing and it worked perfectly. the path Lib/site-packages/OpenGL/GL/DLLS MUST have the dll file. No other thing required. No cmake or Visual C++ as may some sites suggest.

Sharisharia answered 18/2 at 11:56 Comment(1)
Another non-working solution. You made me create this folder and store in there the dlls but the error still cries out loud.Brittneybrittni

© 2022 - 2024 — McMap. All rights reserved.