You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python2.7+PyOpenGL运行报错:NameError: global name 'BaseFunction' is not defined

解决PyOpenGL中NameError: global name 'BaseFunction' is not defined的问题

Hey there! Let's break down this frustrating error you're hitting while following thenewboston's Pygame tutorial. That NameError referencing BaseFunction is nearly always a sign of a broken or incompatible PyOpenGL installation in your Anaconda-Spyder 3.3.4 (Python 2.7) environment.

First, let's recap the error trace you shared to align on the issue:

Traceback (most recent call last):
File "<ipython-input-8-72d57f8b0dbe>", line 1, in <module>
glEnd()
File "/home/cadu/anaconda2/lib/python2.7/site-packages/OpenGL /latebind.py", line 61, in __call__
return self.wrapperFunction( self.baseFunction, *args, **named )
File "/home/cadu/anaconda2/lib/python2.7/site-packages/OpenGL/GL/exceptional.py", line 45, in glEnd
return BaseFunction( )
NameError: global name 'BaseFunction' is not defined

What's causing this?

The exceptional.py module in PyOpenGL tries to use BaseFunction but hasn't imported it properly. This usually happens for one of these reasons:

  • The PyOpenGL package was corrupted during installation
  • You installed a PyOpenGL version that drops support for Python 2.7 (since Python 2.7 is end-of-life, newer versions don't support it)
  • There's a dependency conflict in your Anaconda environment

Step-by-step fix:

  1. Uninstall the broken PyOpenGL installation
    Open your Anaconda prompt and run:

    conda uninstall -y pyopengl pyopengl-accelerate
    # If conda doesn't locate the packages, use pip instead:
    pip uninstall -y pyopengl pyopengl-accelerate
    
  2. Reinstall a Python 2.7-compatible version
    The last PyOpenGL versions that support Python 2.7 are 3.1.5. Install them with:

    pip install pyopengl==3.1.5 pyopengl-accelerate==3.1.5
    

    We use pip here because conda's repository might not have these older, Python 2.7-friendly versions readily available.

  3. Verify the fix
    In Spyder, run this minimal test code to confirm glEnd() works without errors:

    from OpenGL.GL import glBegin, glEnd, GL_LINES
    glBegin(GL_LINES)
    glEnd()
    

Quick tweak for your cube code:

I noticed your glRotatef(20, 0, 0, 0) line—setting all axis parameters to 0 means the cube won't rotate at all. Try changing it to glRotatef(20, 1, 1, 0) to get a smooth spinning effect once the error is fixed!

内容的提问来源于stack exchange,提问作者Carlos_kuro

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 05:18:18