Mouse.py in demos giving TypeError: unsupported operand type(s) for /: 'tuple' and 'int'

Hi all,

I was trying to run mouse.py in demos section of Psychopy. I am using the recent standalone version of Psychopy on MAC OS sierra.

Can anyone help me to understand why I am getting following error?

Traceback (most recent call last):
  File "/Applications/PsychoPy2.app/Contents/Resources/lib/python2.7/psychopy/demos/coder/input/mouse.py", line 41, in <module>
    mouse_dX, mouse_dY = myMouse.getRel()
  File "/Applications/PsychoPy2.app/Contents/Resources/lib/python2.7/psychopy/event.py", line 655, in getRel
    relPos = self.getPos()
  File "/Applications/PsychoPy2.app/Contents/Resources/lib/python2.7/psychopy/event.py", line 558, in getPos
    lastPosPix = lastPosPix - self.win.size / 2
TypeError: unsupported operand type(s) for /: 'tuple' and 'int'
1.8979 	WARNING 	Monitor specification not found. Creating a temporary one...

Thanks in Advance!

I ran into this error as well. As far as I can tell, it seems to be related to a small bug in the event.py file that deals with calculating the updated mouse position. If you look on line 558 in this file, you’ll see this:

lastPosPix = lastPosPix - self.win.size / 2

The problem is that self.win.size here is a tuple, which does not support elementwise division or subtraction. However, lastPosPix is a numpy array, which does support these operations. I fixed this bug by editing this line like so:

lastPosPix = lastPosPix - numpy.array(self.win.size) / 2

That got things working for me. Hope that helps.

2 Likes

Thanks ! It helped :slight_smile:

Yes, this has been fixed in the main release now

Thanks Jon. I was using the previous package of Psychopy. Now it works fine :slight_smile:

The problem is still present in 1.85.6 and 1.85.3 (maybe the bug fix got lost?)

1 Like

I can confirm it’s still there in 1.85.6 ! why ? (the windows bug with the problem of encoding the name of the sound card is still there too !)