PyOpenGL glutInit NullFunctionError

2019-01-22 08:17发布

问题:

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

回答1:

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/



回答2:

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 :)



回答3:

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.



回答4:

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.



回答5:

for python 2.7, PyopenGL needs vc++ 9 compiler, download and install it.

then:

python -m pip install --upgrade pip

pip install image

pip install numpy

pip install PyOpenGL PyOpenGL_accelerate

I downloaded freeglut

unzipped it and added bin directory to the path when calling: glutCreateWindow("sometitle") changed to glutCreateWindow(b'sometitle')

and got it run on windows 7



回答6:

Yes, this happened to me on Windows 10 running python 2.713 anaconda 4 64 bit. I had used conda to install pyopengl but received the same error as above. So I downloaded freeglut from transmissionzero and just copied the freeglut.dll (64 bit for me) to the same directory as my source file (it just needs to be in the dll searchpath) and all was good.



回答7:

I know it is a little late. I also encountered this problem with python 2.7 (32 bits) in windows. I tried the method mentioned by user2723240 but still failed. Finally, I solved this problem by copying glue32.dll to System32 in C drive and copy glue32.dll into my source file directory. It works well now.



回答8:

I got the same error and a solved installing required files from here.

Download these files:

  • PyOpenGL-3.1.1-cp27-cp27m-win32.whl (download if your computer 32 bits )

  • PyOpenGL-3.1.1-cp27-cp27m-win_amd64.whl (download if your computer 64 bits )

  • PyOpenGL_accelerate-3.1.1-cp27-cp27m-win32.whl (download if your computer 32 bits )

  • PyOpenGL_accelerate-3.1.1-cp27-cp27m-win_amd64.whl (download if your computer 64 bits )

install these .whl files for 64 bits:

pip install PyOpenGL-3.1.1-cp27-cp27m-win_amd64.whl
pip install PyOpenGL_accelerate-3.1.1-cp27-cp27m-win_amd64.whl

install these .whl files for 32 bits:

pip install PyOpenGL-3.1.1-cp27-cp27m-win32.whl 
pip install PyOpenGL_accelerate-3.1.1-cp27-cp27m-win32.whl


回答9:

On linux, the pyopengl module attempts to use ctypes module to load the glut library as simply 'glut'. According to ctypes documentation the loadLibrary routine must be given the complete filename. Therefore, I made a symbolic link to libglut.so and named it 'glut' and everything just worked.



回答10:

My case is different, Python 3.6 and windows 10. However exactly same error message. Tried all above solutions, no success. Downloaded WHL file right to my computer and version of python from HERE

Then pip installs filename.Whl, no more issue!

The answer was from a Chinese website: Answer Link



回答11:

The folowing should work for Anaconda users:

conda install - c conda-forge freeglut

https://anaconda.org/conda-forge/freeglut