PyOpenGL glutInit NullFunctionError
I am running Anaconda Python 2.7 on a Win7 x64 machine and used
pip install PyOpenGL PyOpenGL_accelerate
at the Anaconda command line to install PyOpenGL.
I have some code (not my own I must confess) that makes use of glutInit
import sys
import math
import numpy
import OpenGL
from OpenGL.GL import *
from OpenGL.GLUT import *
import Image
import linkage
# ... a whole load of definitions etc ...
glutInit(sys.argv)
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
glutInitWindowSize(600, 600)
glutCreateWindow('linkage')
init()
initWindow()
glutIdleFunc(idle)
glutMainLoop()
I run by entering the following at the command line:
python main.py peaucellier.txt
But then get the following error (line 371 is the glutInt(sys.argv) line above)
File "C:/Users/Owner/Documents/Python Scripts/linkage/main.py", line 371, in <module>
glutInit(sys.argv)
File "C:\Anaconda\lib\site-packages\OpenGL\GLUT\special.py", line 333, in glutInit
_base_glutInit( ctypes.byref(count), holder )
File "C:\Anaconda\lib\site-packages\OpenGL\platform\baseplatform.py", line 407, in __call__
self.__name__, self.__name__,
NullFunctionError: Attempt to call an undefined function glutInit, check for bool(glutInit) before calling
I have looked at similar errors posted in this forum but none of the proposed fixes are working which is why I'm asking, what's wrong here?
Is the installation at fault? Are the imports correct?
EDIT: After trying many many fixes for the official release I am now using an unofficial release that works perfectly from Unofficial Windows Binaries for Python Extension Packages
Solution 1:
According to the link below the problem was with the glut installation rather than pip install
. It seems glut files are not part of PyOpenGL or PyOpenGL_accelerate package. You have to download them seperately.
https://stackoverflow.com/a/39181193/7030177
Windows user can use the link below to download glut as mentioned in the given link. ftp://ftp.sgi.com/opengl/glut/glut3.html.old#windows
Linux Users can just install glut using the following command:
sudo apt-get install freeglut3-dev
Hope this helps :)
Solution 2:
After looking around for a solution to a similar problem I ran across this google group that answers the question: https://groups.google.com/forum/#!topic/glumpy-users/aC1NjEHXtEE
There is a problem with OpenGL.GLUT when downloaded as pip from the official source. Uninstall OpenGL using pip
, then download OpenGL from http://www.lfd.uci.edu/~gohlke/pythonlibs/
Solution 3:
If installing PyOpenGL from easy_install, pip or conda, make sure that you have already installed a GLUT implementation, such as FreeGLUT (prebuilt Windows binaries).
For FreeGLUT, copy the distributed files to a location on your hard drive and then add the path to the bin directory (which contains the GLUT DLLs) to your PATH environment variable. Then PyOpenGL should work as expected.
Solution 4:
For people on Linux with this error after installing via easy_install PyOpenGL
or pip install PyOpenGL
.
-> Install the distribution package as: sudo apt-get install python-opengl
- this works for me.