visual.Window() error

I run this code:

from psychopy import visual
import psychopy
width = 1600
height = 900
win = visual.Window(
    size=[width, height],
    units="pix",
    fullscr=False,
    color=[0.475, 0.475, 0.475])

win.flip()
psychopy.event.waitKeys()
win.close()

And I get this error:

Traceback (most recent call last):
  File "C:\Users\ccala\Desktop\rtr.py", line 11, in <module>
    color=[0.475, 0.475, 0.475])
  File "C:\Program Files\Python37\lib\site-packages\psychopy\visual\window.py", line 389, in __init__
    self.backend = backends.getBackend(win=self, *args, **kwargs)
  File "C:\Program Files\Python37\lib\site-packages\psychopy\visual\backends\__init__.py", line 32, in getBackend
    return Backend(win, *args, **kwargs)
  File "C:\Program Files\Python37\lib\site-packages\psychopy\visual\backends\pygletbackend.py", line 101, in __init__
    defDisp = pyglet.window.get_platform().get_default_display()
AttributeError: module 'pyglet.window' has no attribute 'get_platform'

please, help!

1 Like

on another pc i get this other error:

C:\Users\cc18849\PycharmProjects\psychopy\venv\Scripts\python.exe C:/Users/cc18849/PycharmProjects/psychopy/venv/test.py
Traceback (most recent call last):
File “C:/Users/cc18849/PycharmProjects/psychopy/venv/test.py”, line 11, in
color=[0.475, 0.475, 0.475])
File “C:\Users\cc18849\PycharmProjects\psychopy\venv\lib\site-packages\psychopy\visual\window.py”, line 389, in init
self.backend = backends.getBackend(win=self, *args, **kwargs)
File “C:\Users\cc18849\PycharmProjects\psychopy\venv\lib\site-packages\psychopy\visual\backends_init_.py”, line 32, in getBackend
return Backend(win, *args, **kwargs)
File “C:\Users\cc18849\PycharmProjects\psychopy\venv\lib\site-packages\psychopy\visual\backends\pygletbackend.py”, line 101, in init
defDisp = pyglet.window.get_platform().get_default_display()
AttributeError: module ‘pyglet.window’ has no attribute ‘get_platform’
5.6659 WARNING Monitor specification not found. Creating a temporary one…
Exception ignored in: <function Window.del at 0x000001ED2D1C3EA0>
Traceback (most recent call last):
File “C:\Users\cc18849\PycharmProjects\psychopy\venv\lib\site-packages\psychopy\visual\window.py”, line 501, in del
self.close()
File “C:\Users\cc18849\PycharmProjects\psychopy\venv\lib\site-packages\psychopy\visual\window.py”, line 1327, in close
self.backend.close() # moved here, dereferencing the window prevents
AttributeError: ‘NoneType’ object has no attribute ‘close’

Your version of pyglet might be too new. Depending on how you have Python set up, something like pip install pyglet==1.3.2 would downgrade pyglet.

2 Likes

Damien - you are a genius. I just ran into this very same error and your advice solved it for me. Hope you are well! bw, Tom.

Yes, it did solve my issue. Thanks.

Hi! I have a similar problem. I can’t run the “Hello world” demo. I get this message :

Blockquote
8.6459 WARNING Monitor specification not found. Creating a temporary one…
Traceback (most recent call last):
File “C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy\demos\coder\basic\hello_world.py”, line 14, in
win = visual.Window()
File “C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy\visual\window.py”, line 375, in init
self.backend = backends.getBackend(win=self, *args, **kwargs)
File “C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy\visual\backends_init_.py”, line 32, in getBackend
return Backend(win, *args, **kwargs)
File “C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy\visual\backends\pygletbackend.py”, line 138, in init
fullscreen=self._isFullScr,
AttributeError: ‘PygletBackend’ object has no attribute ‘_isFullScr’
Exception AttributeError: “‘NoneType’ object has no attribute ‘close’” in <bound method Window.del of <psychopy.visual.window.Window object at 0x059DDE50>> ignored

So i think it is the same problem. Where i’m gonna write this command? I didn’t understand.

You should be able to run “pip install pyglet==1.3.2” in the terminal

I have Psychopy 1.90.2. I have installed Python 3.6 so i run pip3 install pyglet==1.3.2 and i still get this error message…

I found this post and it seems like it is the same problem you are having. Hopefully this helps.

Thank you very much for your interest! I will check on it and i hope it will help…

I managed to solve the problem. I went to “Preferences” and changed the “Window type” from pyglet to pygame and also clicked the ‘‘full-screen’’ button.Most of the demos are running ok!

Hello everyone, this problem happens to me too and no solution from the above suggested solves it. Is there anything else that can help?

I have python 3.6.6
psychopy 2021 2.3

thank you

Since this topic is listed as solved, I would recommend that you start a new thread, posting the details of your error messages.