Fail at basic drawing: Exception: Call to function "glActiveTexture" before GL context created

I’ve just pip installed psychopy on a 3.8 Python distribution on a fairly recent laptop (2020), with an nvidia GPU and updated drivers.

I’m trying to run this minimal example:

import psychopy.visual, psychopy.core

win = psychopy.visual.Window(size=[800, 600], winType='pygame')
stim = psychopy.visual.Circle(win=win, 
                              units="pix",
                              fillColor="black", 
                              lineColor="black",
                              edges=128, 
                              radius=10, 
                              lineWidth=0.5)
stim.draw()
win.update()

psychopy.core.wait(5.0)
win.close()
psychopy.core.quit()

Unfortunately, with the GLFW or pygame backend (pyglet fails at windows creation with NotImplementedError: abstract), it throws the following error:

pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
C:\Users\Dom\Desktop\WPy64-3860\python-3.8.6.amd64\lib\site-packages\pyglet\media\codecs\wmf.py:838: UserWarning: [WinError -2147417850] Cannot change thread mode after it is set
  warnings.warn(str(err))
C:\Users\Dom\Desktop\WPy64-3860\python-3.8.6.amd64\lib\site-packages\pyglet\gl\gl_info.py:142: UserWarning: No GL context created yet.
  warnings.warn('No GL context created yet.')
C:\Users\Dom\Desktop\WPy64-3860\python-3.8.6.amd64\lib\site-packages\pyglet\gl\gl_info.py:122: UserWarning: No GL context created yet.
  warnings.warn('No GL context created yet.')
C:\Users\Dom\Desktop\WPy64-3860\python-3.8.6.amd64\lib\site-packages\pyglet\gl\gl_info.py:186: UserWarning: No GL context created yet.
  warnings.warn('No GL context created yet.')
Traceback (most recent call last):

  File "test.py", line 27, in <module>
    stim.draw()

  File "C:\Users\Dom\Desktop\WPy64-3860\python-3.8.6.amd64\lib\site-packages\psychopy\visual\shape.py", line 345, in draw
    GL.glActiveTexture(GL.GL_TEXTURE0)

  File "C:\Users\Dom\Desktop\WPy64-3860\python-3.8.6.amd64\lib\site-packages\pyglet\gl\lib_wgl.py", line 91, in __call__
    raise Exception(

Exception: Call to function "glActiveTexture" before GL context created

Is there anything I can do?

The pyglet error Cannot change thread mode after it is set generally comes from having pyglet 1.5 installed (just on windows - it appears to work fine on macOS/ubuntu).
Try pip install pyglet<1.5 to see if that fixes the issue

Hi Jon,

Thanks for your answer. I downgraded pyglet to 1.4.11 version, but unfortunately the error persists :confused:

kind bump

I’m guessing this is some type of driver issue given the error you are getting. I’m able to run the example you posted on a win10 laptop with nvidia gpu using Anaconda Python 3.6 or 3.8 with pyglet 1.4.x, so it is not an issue with your code.

Could you please try running your test again with the winType='pygame' removed or changed to winType='pyglet' and post the exception you get in that case again?

If you could also try running the psychopy\demos\coder\sysInfo.py demo, and provide any output it gives, that might help.

The sysInfo.py fails at from psychopy import visual, preferences:

pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):

  File "<ipython-input-16-2e794dd15cd1>", line 2, in <module>
    from psychopy import visual, preferences

  File "C:\Users\Dom\Desktop\WPy64-3860\python-3.8.6.amd64\lib\site-packages\psychopy\visual\__init__.py", line 29, in <module>
    from .button import ButtonStim

  File "C:\Users\Dom\Desktop\WPy64-3860\python-3.8.6.amd64\lib\site-packages\psychopy\visual\button.py", line 13, in <module>
    from psychopy.visual.shape import BaseShapeStim

  File "C:\Users\Dom\Desktop\WPy64-3860\python-3.8.6.amd64\lib\site-packages\psychopy\visual\shape.py", line 36, in <module>
    from psychopy.contrib import tesselate

  File "C:\Users\Dom\Desktop\WPy64-3860\python-3.8.6.amd64\lib\site-packages\psychopy\contrib\tesselate.py", line 67, in <module>
    tess = gluNewTess()

  File "C:\Users\Dom\Desktop\WPy64-3860\python-3.8.6.amd64\lib\site-packages\pyglet\gl\lib.py", line 101, in errcheck
    raise GLException('No GL context; create a Window first')

GLException: No GL context; create a Window first

Here’s the results of working parts:

System info:
Windows-10-10.0.19041-SP0

Python info
C:\Users\Dom\Desktop\WPy64-3860\python-3.8.6.amd64\python.exe
3.8.6 (tags/v3.8.6:db45529, Sep 23 2020, 15:52:53) [MSC v.1927 64 bit (AMD64)]
numpy 1.19.2
scipy 1.5.3
matplotlib 3.3.2
pyglet 1.4.11
pyo [not installed]

PsychoPy 2020.2.10

OpenGL info:
vendor: 
rendering engine: 
OpenGL version: 0.0.0
(Selected) Extensions:
	 False GL_ARB_multitexture
	 False GL_EXT_framebuffer_object
	 False GL_ARB_fragment_program
	 False GL_ARB_shader_objects
	 False GL_ARB_vertex_shader
	 False GL_ARB_texture_non_power_of_two
	 False GL_ARB_texture_float
	 False GL_STEREO

Weirdly, the OpenGL information comes empty :thinking: I wonder if that’s normal… and why wouldn’t it be, since my laptop is quite recent, has an nvidia GTX GPU and performs decently with GPU-based stuff like games and such :slight_smile:


If I change winType to pyglet (instead of pygame), the following errors comes out:

pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):

  File "C:\Users\Dom\test\test\try_stuff.py", line 9, in <module>
    win = psychopy.visual.Window(size=[800, 600], winType='pyglet')

  File "C:\Users\Dom\Desktop\WPy64-3860\python-3.8.6.amd64\lib\site-packages\psychopy\visual\window.py", line 430, in __init__
    self.backend = backends.getBackend(win=self,

  File "C:\Users\Dom\Desktop\WPy64-3860\python-3.8.6.amd64\lib\site-packages\psychopy\visual\backends\__init__.py", line 74, in getBackend
    return Backend(win, *args, **kwargs)

  File "C:\Users\Dom\Desktop\WPy64-3860\python-3.8.6.amd64\lib\site-packages\psychopy\visual\backends\pygletbackend.py", line 120, in __init__
    allScrs = _default_display_.get_screens()

  File "C:\Users\Dom\Desktop\WPy64-3860\python-3.8.6.amd64\lib\site-packages\pyglet\canvas\base.py", line 101, in get_screens
    raise NotImplementedError('abstract')

NotImplementedError: abstract

Thanks for your help!

This does seem strange.

How did you get sysInfo.py to work the second time, by commenting out the preferences import?

Re: the pyglet / opengl issue, can I ask what the model of the computer and graphics card are? Can you check if there are any windows 10 updates needed for the computer and that you are running with the latest nvidia drivers? Are you running with just the laptop display or are you using two displays?

If you install the latest PsychoPy3 windows standalone installer and run one of the demo’s (or your test script) do you still get the pyglet / opengl issue?

Thanks again.