因为计算机图形学课程需要使用OpenGL画图,不习惯用C++写代码,所以我发现了python也有PyOpenGL库可以实现画图,于是开始了长达半个小时的安装,这里把踩的坑写一下。
首先如果直接pip install PyOpenGL PyOpenGL_accelerate


我直接是安装成功了,然后就以为可以使用了,跑了一下测试代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * def Draw(): glClear(GL_COLOR_BUFFER_BIT) glRotatef(0.5, 0, 1, 0) glutWireTeapot(0.5) glFlush() glutInit() glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA) glutInitWindowSize(400, 400) glutCreateWindow("test") glutDisplayFunc(Draw) glutIdleFunc(Draw) glutMainLoop() if __name__ == '__main__': Draw() |
结果报错:

这个错误网上也很多人说过,我的电脑是64位的,而这个错误无非是直接pip安装只能安装32位的库,因此报错。所以需要手动去下载whl文件安装PyOpenGL。
这里我附上网址:
https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopengl
我这里也把我自己的配置的whl文件放在这儿,我是win10 + python3.7 + 64位,
PyOpenGL_accelerate-3.1.5-cp37-cp37m-win_amd64
提取码:hglu
将压缩包下载解压,然后进入PyOpenGL-3.1.5-cp37-cp37m-win_amd64.whl对应目录,pip install PyOpenGL-3.1.5-cp37-cp37m-win_amd64.whl等待安装完成即可,这样就可以在python中使用OpenGL。
示例代码结果:
