PyOpenGL 安装中出现的错误 Attempt to call an undefined function glutInit, check for bool(glutInit) before ca

版权声明:本文为博主原创文章,转载时请注明文章出处和作者! https://blog.csdn.net/sb985/article/details/80627019
Traceback (most recent call last):
  File "demo.py", line 10, in <module>
    glutInit()
  File "/home/yuan/anaconda3/lib/python3.6/site-packages/OpenGL/GLUT/special.py", line 333, in glutInit
    _base_glutInit( ctypes.byref(count), holder )
  File "/home/yuan/anaconda3/lib/python3.6/site-packages/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

今天在Ubuntu上安装pyopengl,运行时出错,在官网上查,说要下载一些额外的包比如pygame等等,首先建议不要下载,错误不在此,
这个原因我在网上看了看主要说的是因为机器位数不对,用pip默认下载的是32位的,而大多数机子都是64位的,所以改改这个包的配置就行.

在ubuntu上

安装两个软件
sudo apt-get install freeglut3
sudo apt-get install freeglut3-dev
如果还是不行,就
sudo apt-get install python-opengl,这个我没试过

在windows上

下载下载glut32.dll或glut64.dll,如果是32位系统复制到C:\Windows\System32目录下,如果是

64位系统复制到C:\Windows\SysWOW64目录下。如果提示有同名文件,最好选择跳过而不要替换

测试代码:

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

def drawFun():
    glClear(GL_COLOR_BUFFER_BIT)
    glutWireTeapot(0.5)
    glFlush()

glutInit()
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA)
glutInitWindowSize(400,400)
glutCreateWindow("First")
glutDisplayFunc(drawFun)
glutMainLoop()

参考博客:
1.http://blog.sina.com.cn/s/blog_8d2b2be40102w3s1.html
2.https://blog.csdn.net/u013166622/article/details/50831467?spm=a2c4e.11155472.blogcont.3.446a759bKENqhT
3.https://stackoverflow.com/questions/26700719/pyopengl-glutinit-nullfunctionerror
4.https://blog.csdn.net/u010663979/article/details/52925911
5.http://www.cnblogs.com/gamesun/archive/2013/06/12/3133087.html

猜你喜欢

转载自blog.csdn.net/sb985/article/details/80627019