Python 安装OpenGL 在windows_64下利用命令: pip install pyopengl 安装python的openGL环境。结果运行示例代码出现以下错误:

Python环境搭建之OpenGL

以下内容为我python OpenGl 环境搭建历程:

  win7 64位操作系统,python3.5.3 ,无其他相关。

  直接cmd或PowerShell输入以下命令:

pip install  PyOpenGL PyOpenGL_accelerate
 
   

在windows_64下利用命令:

pip install pyopengl 安装python的openGL环境。结果运行示例代码出现以下错误: 

OpenGL.error.NullFunctionError: Attempt to call an undefined function glutInitDisplayMode, check for bool(glutInitDisplayMode) before calling

原因分析

主要是你的windows是64位的,但是使用命令pip install pyopengl 安装后,执行示例默认使用的是pyopengl_32位的,所以出现了以上错误!

解决方案

在Windows_64上安装64位的pyopengl 即可,pyopengl_64位下载链接:

https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopengl下载与自己Python版本合适的,执行命令:pip install XXX.whl 即可正常使用pyopengl环境。

测试环境代码

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

def drawFunc():
    glClear(GL_COLOR_BUFFER_BIT)
    #glRotatef(1, 0, 1, 0)
    glutWireTeapot(0.5)
    glFlush()

glutInit()
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA)
glutInitWindowSize(400, 400)
#参数为b类型而不是string
glutCreateWindow(b"First")
glutDisplayFunc(drawFunc)
#glutIdleFunc(drawFunc)
glutMainLoop() 
原文:https://blog.csdn.net/feilong_csdn/article/details/61421002

猜你喜欢

转载自blog.csdn.net/jacke121/article/details/80711614
今日推荐