Psychopy- error when I run the experiment

I’m a Master’s student and I can’t run an experience in psychopy because when I run it, it gives me an error.

######## Running: C:\Users\labch\Desktop\ultimato_quasefinal_lastrun.py ########
29.8031 INFO Loaded monitor calibration from [‘2020_02_04 13:11’]
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
3.8977 WARNING We strongly recommend you activate the PTB sound engine in PsychoPy prefs as the preferred audio engine. Its timing is vastly superior. Your prefs are currently set to use [‘sounddevice’, ‘pyo’, ‘pygame’] (in that order).
Traceback (most recent call last):
File “C:\Users\labch\Desktop\ultimato_quasefinal_lastrun.py”, line 72, in
units=‘height’)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\window.py”, line 465, in init
self.backend = backends.getBackend(win=self, backendConf=backendConf)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\backends_init_.py”, line 76, in getBackend
return Backend(win, *args, **kwargs)
TypeError: Can’t instantiate abstract class PygameBackend with abstract methods getMousePos, onMouseButton, onMouseButtonPress, onMouseButtonRelease, onMouseEnter, onMouseLeave, onMouseMove, onMouseScroll, setCurrent, setMouseCursor, setMouseExclusive, setMousePos
Exception ignored in: <bound method Window.del of <psychopy.visual.window.Window object at 0x0000020500197128>>
Traceback (most recent call last):
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\window.py”, line 616, in del
self.close()
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\window.py”, line 2426, in close
self.backend.close() # moved here, dereferencing the window prevents
AttributeError: ‘NoneType’ object has no attribute ‘close’

Experiment ended.

Can anyone understand why it’s not working and help me?
Thank you.

1 Like

Please let me see the details of your code so I can make a judgment

I am getting the same problems. code is just simply:

from psychopy import visual, core, event, data
mywin = visual.Window([800,600], monitor="testMonitor", units="deg",winType='pygame')

then i get the error below:

pygame 2.5.2 (SDL 2.28.3, Python 3.8.18)
Hello from the pygame community. Contribute - pygame wiki
Traceback (most recent call last):
File “/Users/arnavjaiswal/Documents/University/FYP/Codebase/main.py”, line 5, in
mywin = visual.Window([800,600], monitor=“testMonitor”, units=“deg”,winType=‘pygame’)
File “/opt/anaconda3/envs/FYPEnv/lib/python3.8/site-packages/psychopy/visual/window.py”, line 469, in init
self.backend = backends.getBackend(win=self, backendConf=backendConf)
File “/opt/anaconda3/envs/FYPEnv/lib/python3.8/site-packages/psychopy/visual/backends/init.py”, line 61, in getBackend
return Backend(win, *args, **kwargs)
TypeError: Can’t instantiate abstract class PygameBackend with abstract methods getMousePos, onMouseButton, onMouseButtonPress, onMouseButtonRelease, onMouseEnter, onMouseLeave, onMouseMove, onMouseScroll, setCurrent, setMouseCursor, setMouseExclusive, setMousePos
Exception ignored in: <function Window.del at 0x7fa7ed4dff70>
Traceback (most recent call last):
File “/opt/anaconda3/envs/FYPEnv/lib/python3.8/site-packages/psychopy/visual/window.py”, line 647, in del
self.close()
File “/opt/anaconda3/envs/FYPEnv/lib/python3.8/site-packages/psychopy/visual/window.py”, line 2536, in close
self.backend.close() # moved here, dereferencing the window prevents
AttributeError: ‘NoneType’ object has no attribute ‘close’

I ran into the same error, when I switched winType to pygame from pyglet in the process of troubleshooting why event.Mouse instances were not registering clicks or movement.

For context, our group has a complex PsychoPy application and have recently attempted to update our virtualenv using the latest PsychoPy (--no-deps with select manual dependency install) and latest dependencies.

It looks like Python is complaining because of an attempt to instantiate a class that contains abstract methods, e.g. PygameBackend.getMousePos() has the @abstractmethod decorator, meaning it is not a callable method, but a sort of “placeholder” defining the interface, intended to be implemented by a subclass.

If I understand correctly, when we try to create a window like so Window(..., winType='pygame'), PsychoPy looks at the winType and attempts to instantiate a Window with a PygameBackend. Since that class has abstract methods, Python sees it as an abstract class, will not instantiate it and throws the error we’re seeing.

I guess I’m confused, is PygameBackend not meant to be a fully-implemented window backend type, or?