【发布时间】:2020-09-16 16:30:33
【问题描述】:
对于 Python 项目,我需要 PyOpenGL。我已经用 PyCharm IDE 安装了它。
当我运行 OpenGL 程序测试安装时,出现以下错误消息:
OpenGL.error.NullFunctionError: Attempt to call an undefined function glutInit, check for bool(glutInit) before calling.
我在 www 中搜索了可能的解决方案,并在 StackOverflow 找到了一些解决方案。我尝试了所有这些,但都没有奏效。
然后我在这里找到了那个博客:
https://block.arch.ethz.ch/blog/2016/10/pyopengl-glut-error/
我按照所有说明操作并在 PyCharm IDE 中收到以下错误消息:
(virtual-environment) C:\Users\Rainer\PycharmProjects\MatchMover>pip install C:\Users\Rainer\Desktop\PyOpenGL-3.1.5-cp36-cp36m-win_amd64.whl
PyOpenGL-3.1.5-cp36-cp36m-win_amd64.whl is not a supported wheel on this platform.
You are using pip version 9.0.1, however version 20.0.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
pip 包已经手动更新到 20.0.2 版本,但与 PyCharm IDE 不同步。
我使用的是 Windows 7 计算机、Python 3.6.3、PyOpenGL-3.1.5-cp36-cp36m-win_amd64.whl 作为 OpenGL 库,我使用 freeglut。
这里是测试程序(取自:https://codeloop.org/python-opengl-programming-creating-window/):
main.py
from OpenGL.GL import *
from OpenGL.GLUT import *
width, height = 500, 400
def draw():
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
glutSwapBuffers()
glutInit()
glutInitDisplayMode(GLUT_RGBA )
glutInitWindowSize(width, height)
glutInitWindowPosition(200, 200)
window = glutCreateWindow("Opengl Window In Python")
glutDisplayFunc(draw)
glutIdleFunc(draw)
glutMainLoop()
【问题讨论】:
-
"PyOpenGL-3.1.5-cp36-cp36m-win_amd64.whl 不是该平台支持的轮子。" 表示您的 Python 是 3.6 或不是 64 -bit(不是 amd64)。也许你的 Python 是 32 位的。使用 32 位轮子或安装 64 位 Python。
-
import sys, print(sys.executable)应该显示真正使用的版本。也可以试试print(sys.version)和print(sys.version_info) -
我的猜测是您正在使用您希望使用的 Python 解释器进行 npt。修复环境变量
PATH。 -
@phd 非常感谢您的帮助!我能够安装 PyOpenGL 而没有任何错误!我的 Python 是 32 位的。我已经安装了 32 位的轮子。测试程序也能正常运行!
-
@joe 也感谢您的帮助!
标签: python opengl pip pyopengl