即使使用 dll(Pyopengl3/Python3.8/Windows10-64) 也无法识别过剩方法

Glut methods not recognised even with dll's(Pyopengl3/Python3.8/Windows10-64)

在运行 Pyopengl3.1.5(Python3.8- Windows10Pro/64bit) 通过Pip安装的主脚本上,编译器没有' 识别 Glut 方法。

遵循这些 Whosebug 答案后(1 & ) ie.reinstalling Pyopengl wheel & putting dll's 在主脚本文件夹中(C:..Python\…\site-packages - PyOpengl 的主目录) ,Environment Path,System32 & SysWow64 ,编译器仍然给出同样的错误:

import OpenGL.GLUT  
glutInit()
NameError: name 'glutInit' is not defined (# checked for casetype )

但是,在 Site-packages\Opengl\Glut 中有一个名为 "special.py" 的 python 脚本,它在将 glutinit 方法的路径添加到 [=26= 时具有过剩方法 defined.So ]init.py (Glut目录)编译,编译器仍然报如下错误。

OpenGL\GLUT\special.py:- def glutInit(INITIALIZED = False)   

OpenGL\GLUT\init.py:- from OpenGL.GLUT.special import *
                      from OpenGL.GLUT.special import glutInit (#added)  


OpenGL\GLUT\main.py:- import OpenGL.GLUT
                      import OpenGL.GLUT.special(#added) 
                      import OpenGL.GLUT.special.glutInit (#added)   

                      glutInit(INITIALIZED = True)  (# function call)

                      ModuleNotFoundError: No module named 'OpenGL.GLUT.special.glutInit'; 'OpenGL.GLUT.special' is not a package  

所以问题是 - 如何让 编译器识别 special.py 中的过剩方法并且还有有什么方法可以更新 .pyc 文件 以反映更新后的 init.py 导入路径?

主要 Pyopengl 脚本 (stackabuse.com)

import OpenGL
import OpenGL.GL
import OpenGL.GLUT
import OpenGL.GLUT.special #(added)
import OpenGL.GLUT.special.glutInit #(added)
import OpenGL.GLU
print("Imports successful!")

w, h = 500,500

# define square 
def square():
    # We have to declare the points in this sequence: bottom left, bottom right, top right, top left
glBegin(GL_QUADS) # Begin the sketch
glVertex2f(100, 100) # Coordinates for the bottom left point
glVertex2f(200, 100) # Coordinates for the bottom right point
glVertex2f(200, 200) # Coordinates for the top right point
glVertex2f(100, 200) # Coordinates for the top left point
glEnd() # Mark the end of drawing


# draw square
def showScreen():
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # Remove everything from screen (i.e. displays all white)
    glLoadIdentity() # Reset all graphic/shape's position
    square() # Draw a square using our function
    glutSwapBuffers()

# Initialise and create Opengl screen
glutInit(True)
glutInitDisplayMode(GLUT_RGBA) # Set the display mode to be colored
glutInitWindowSize(500, 500)   # Set the w and h of your window
glutInitWindowPosition(0, 0)   # Set the position at which this windows should appear
wind = glutCreateWindow("OpenGL Coding Practice") # Set a window title
glutDisplayFunc(showScreen)
glutIdleFunc(showScreen) # Keeps the window open
glutMainLoop()  # Keeps the above created window displaying/running in a loop

要么在每次函数调用时都必须在模块路径之前:

例如:

glutInit(True)

OpenGL.GLUT.glutInit()

或者您必须使用 from 子句更改 import statements

例如:

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