python - PyOpenGL glutInit NullFunctionError

标签 python python-3.x python-2.7 glut pyopengl

我在 Win7 x64 机器上运行 Anaconda Python 2.7 并使用

pip install PyOpenGL PyOpenGL_accelerate

在 Anaconda 命令行安装 PyOpenGL。

我有一些使用 glutInit 的代码(我必须承认不是我自己的)

import sys
import math
import numpy

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

import Image

import linkage

# ... a whole load of definitions etc ...

glutInit(sys.argv)
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
glutInitWindowSize(600, 600)
glutCreateWindow('linkage')
init()
initWindow()
glutIdleFunc(idle)
glutMainLoop()

我通过在命令行输入以下内容来运行:

python main.py peaucellier.txt

但是随后出现以下错误(第 371 行是上面的 glutInt(sys.argv) 行)

File "C:/Users/Owner/Documents/Python Scripts/linkage/main.py", line 371, in <module>
glutInit(sys.argv)

File "C:\Anaconda\lib\site-packages\OpenGL\GLUT\special.py", line 333, in glutInit
_base_glutInit( ctypes.byref(count), holder )

File "C:\Anaconda\lib\site-packages\OpenGL\platform\baseplatform.py", line 407, in __call__
self.__name__, self.__name__,

NullFunctionError: Attempt to call an undefined function glutInit, check for bool(glutInit) before calling

我已经查看了此论坛中发布的类似错误,但建议的修复均不起作用,这就是为什么我要问,这里出了什么问题?

安装有问题吗?导入正确吗?

编辑:在尝试了官方版本的许多修复之后,我现在使用一个非官方版本,它可以从 Unofficial Windows Binaries for Python Extension Packages 完美运行。

最佳答案

根据下面的链接,问题出在过剩安装上,而不是pip install。看来 glut 文件不是 PyOpenGL 或 PyOpenGL_accelerate 包的一部分。您必须单独下载它们。

https://stackoverflow.com/a/39181193/7030177

Windows 用户可以使用下面的链接下载 glut,如给定链接中所述。 ftp://ftp.sgi.com/opengl/glut/glut3.html.old#windows

Linux 用户可以使用以下命令安装 glut:

sudo apt-get install freeglut3-dev

希望这有帮助:)

关于python - PyOpenGL glutInit NullFunctionError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26700719/

相关文章:

Python3无法建立连接socket.gai错误: Name or service not known

python - 使用月费计算正确的实际利率

Python:如何识别字符串中的十进制数字?

Python 无法导入模块 virtualenvwrapper.hook_loader?

python - django 教程中的 {% some %} 语法

python - PyArray_SimpleNewFromData 示例

python - 与数据框中不存在的索引聚合

django - 我可以在 Django 1.11 中使用 Python 3.7 吗?

python-3.x - 错误: AlreadyExistsError - Cannot exceed quota for PoliciesPerRole: 10

python-2.7 - 如何在 python 2.7 windows 10 中安装 difflib 模块