以正常IDLE运行此代码完全可以。
import OpenGL.GL as gl
但是在VSCode中,出现导入错误。
No module named 'OpenGL.GL'; 'OpenGL' is not a package
File "C:\Users\Fluffy\Desktop\OpenGL.py", line 1, in <module>
import OpenGL.GL as gl
File "C:\users\fluffy\desktop\<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\users\fluffy\desktop\<frozen importlib._bootstrap_external>", line 678, in exec_module
File "C:\users\fluffy\desktop\<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "C:\users\fluffy\desktop\<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "C:\users\fluffy\desktop\<frozen importlib._bootstrap>", line 971, in _find_and_load
File "C:\users\fluffy\desktop\<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\users\fluffy\desktop\<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
File "C:\users\fluffy\desktop\<frozen importlib._bootstrap>", line 971, in _find_and_load
File "C:\Users\fluffy\Desktop\OpenGL.py", line 1, in <module>
import OpenGL.GL as gl
此外,我卸载了PyOpenGL,并注意到VSCode的intellisense在python中找到了一个现有的OpenGL模块: link
我很确定它与VSCode从python导入模块的方式有关。
注意:我尝试以多种不同方式重新安装PyOpenGL,但错误仍然存在。