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

问题描述 投票:1回答:1

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

遵循这些stackoverflow答案(12之后,即重新安装Pyopengl wheel并将dll's放入主脚本文件夹(C:.. Python \…\ site-packages-PyOpengl的主目录),环境路径,System32和SysWow64,编译器仍会给出相同的错误:

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

但是,在Site-packages \ Opengl \ Glut中有一个名为“ special.py”的python脚本,其中定义了glut方法。因此,将glutinit方法的路径添加到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中的glut方法],并且还有任何更新.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

在通过Pip安装的Pyopengl3.1.5(Python3.8- Windows10Pro / 64bit)中运行主脚本时,编译器无法识别Glut方法。在遵循了这些stackoverflow答案(1&2)之后,即...

python python-3.x windows pyopengl pyc
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.