PyOpenGL :: OpenGL.error.NullFunctionError:尝试调用未定义的函数 glutInit,在调用之前检查 bool(glutInit)

Fra*_*ani 12 python opengl pyopengl visual-c++ visual-studio-2017-build-tools

我正在遵循这个非常简单的指南,以便迈出进入 PyOpenGL 的第一步。

\n
    \n
  1. 我安装了pip install PyOpenGL PyOpenGL_accelerate,一切都好。

    \n
  2. \n
  3. 我通过测试代码测试了安装:

    \n

    import OpenGL.GL\nimport OpenGL.GLUT\nimport OpenGL.GLU\nprint("导入成功!") # 如果您看到此信息打印到控制台,则安装成功

    \n
  4. \n
\n

都好

\n

我现在运行这个脚本:

\n
from OpenGL.GL import *\nfrom OpenGL.GLUT import *\nfrom OpenGL.GLU import *\n\nw,h= 500,500\ndef square():\n    glBegin(GL_QUADS)\n    glVertex2f(100, 100)\n    glVertex2f(200, 100)\n    glVertex2f(200, 200)\n    glVertex2f(100, 200)\n    glEnd()\n\ndef iterate():\n    glViewport(0, 0, 500, 500)\n    glMatrixMode(GL_PROJECTION)\n    glLoadIdentity()\n    glOrtho(0.0, 500, 0.0, 500, 0.0, 1.0)\n    glMatrixMode (GL_MODELVIEW)\n    glLoadIdentity()\n\ndef showScreen():\n    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)\n    glLoadIdentity()\n    iterate()\n    glColor3f(1.0, 0.0, 3.0)\n    square()\n    glutSwapBuffers()\n\nglutInit()\nglutInitDisplayMode(GLUT_RGBA)\nglutInitWindowSize(500, 500)\nglutInitWindowPosition(0, 0)\nwind = glutCreateWindow("OpenGL Coding Practice")\nglutDisplayFunc(showScreen)\nglutIdleFunc(showScreen)\nglutMainLoop()\n
Run Code Online (Sandbox Code Playgroud)\n

我收到的错误是OpenGL.error.NullFunctionError: Attempt to call an undefined function glutInit, check for bool(glutInit) before calling

\n

所以我在网上阅读了一些指南,他们指出从这里下载轮子。所以我继续下载PyOpenGL_accelerate\xe2\x80\x913.1.5\xe2\x80\x91cp38\xe2\x80\x91cp38\xe2\x80\x91win_amd64.whlPyOpenGL\xe2\x80\x913.1.5\xe2\x80\x91cp38\xe2\x80\x91cp38\xe2\x80\x91win_amd64.whl因为我正在跑步Python 3.8

\n
    \n
  1. pip install .\\PyOpenGL_accelerate-3.1.5-cp39-cp39-win_amd64.whl回报PyOpenGL-accelerate is already installed with the same version as the provided wheel. Use --force-reinstall to force an installation of the wheel.
  2. \n
  3. pip install .\\PyOpenGL_accelerate-3.1.5-cp38-cp38-win_amd64.whl回报PyOpenGL-accelerate is already installed with the same version as the provided wheel. Use --force-reinstall to force an installation of the wheel.
  4. \n
\n

如此简单的指南怎么会导致我如此痛苦的结果呢?

\n

如何检查是否Visual C++ 14.0 build tools已安装。也许这是我唯一缺少的一步?

\n

Rab*_*d76 16

由于“Python 扩展包的非官方 Windows 二进制文件”不再存在(请参阅Christoph Gohlke 的 Windows Wheels 站点将于月底关闭),以下解决方案不再有效:

\n \n包中缺少 _freeglut_ DLL。\n

卸载“PyOpenGL”:

\n
pip uninstall pyopengl\n
Run Code Online (Sandbox Code Playgroud)\n

从Python 扩展包的非官方 Windows 二进制文件下载包轮(例如:“PyOpenGL\xe2\x80\x913.1.6\xe2\x80\x91cp311\xe2\x80\x91cp311\xe2\x80\x91win_amd64.whl”)并安装它:

\n
pip install PyOpenGL\xe2\x80\x913.1.6\xe2\x80\x91cp311\xe2\x80\x91cp311\xe2\x80\x91win_amd64.whl\n
Run Code Online (Sandbox Code Playgroud)\n \n
\n

或者,可以在这里找到轮子:https://drive.google.com/drive/folders/1mz7faVsrp0e6IKCQh8MyZh-BcCqEGPwx

\n
\n

如果您找不到满足您需求的轮子,则需要克隆mcfletch/pyopengl存储库并从存储库安装 PyOpenGL(另请参阅PyOpenGL 和 PyOpenGL_Accelerate):

\n

克隆存储库:

\n
git clone https://github.com/mcfletch/pyopengl\n
Run Code Online (Sandbox Code Playgroud)\n

安装pyopenglpyopengl_accelerate

\n
cd pyopengl\npip install -e .\ncd accelerate\npip install -e .\n
Run Code Online (Sandbox Code Playgroud)\n