ioHub with PsychoPy 2020.1.2 (on macOS 10.14.6)

Hi there,

I try to start the iohub-process on a mac (macOS Mojave 10.14.6) with the recently published version of PsychoPy3 (v2020.1.2). I downloaded the standalone for macOS, but I get the same results when installing via brew or pip. With the basic code:

from psychopy.iohub import launchHubServer
io = launchHubServer()

I get the error message:

v2020.1.2
## Running: /Users/maltemaxmoller/Documents/Projekte/PsychoPy/PsychoPy3/ioHub_Startup.py ##
ioHub Server Process Completed With Code:  -15
Traceback (most recent call last):
  File "/Users/maltemaxmoller/Documents/Projekte/PsychoPy/PsychoPy3/ioHub_Startup.py", line 2, in <module>
    io = launchHubServer()
  File "/Applications/PsychoPy3.app/Contents/Resources/lib/python3.6/psychopy/contrib/lazy_import.py", line 120, in __call__
    return obj(*args, **kwargs)
  File "/Applications/PsychoPy3.app/Contents/Resources/lib/python3.6/psychopy/iohub/client/connect.py", line 262, in launchHubServer
    return ioHubConnection(iohub_config)
  File "/Applications/PsychoPy3.app/Contents/Resources/lib/python3.6/psychopy/iohub/client/__init__.py", line 296, in __init__
    raise RuntimeError('Error starting ioHub server: {}'.format(self.iohub_status))
RuntimeError: Error starting ioHub server: ioHub startup failed.
##### Experiment ended. #####

I also granted PsychoPy3 app access to the computer in the “security” tab of the system preferences (PsychoPy3 does not start at all when the option is disabled). The same code works fine with PsychoPy v1.90.3 (with all the dependencies installed) on the same machine, but I get the same error message with v2020.1.1 as well as older versions of PsychoPy3 (like v3.2.4). Also the ioHub demos included in PsychoPy3 (tested with keyboard.py, keyboardreactiontime.py, launchHub.py, and mouse.py) fail to work and raise the same error message.

Is this a known problem and can someone point me towards a solution? I found some related older posts about the topic (e.g., here and here), but could not determine whether the problem has been solved.

Best regards and thanks for any advice!

Malte

As of spring / summer 2019 iohub was working on macOS but I have not tested it myself on macOS since then. If you are wanting to use iohub for keyboard events, using the psychopy.hardware.Keyboard class is a better option now, as it has better timing on macOS.

Hi Sol and thanks for the quick reply!

I solely used ioHub to detect keypress/mouse events in the past. I recently learned about the hardware.Keyboard class and it will replace ioHub in my scripts. However, the reason I tested the ioHub on my Mac was that I am looking for ways to implement eye tracking devices in PsychoPy. I found the documentation on how to do it with ioHub very detailed and informative. I will give the ioHub another try on a different Mac tomorrow and see if it works out. Perhaps it has something to do with my specific system configuration.

Best regards,

Malte

I never solved the problems. My errors were essentially the same. Please keep me informed. I would like to use a tobii eye tracker. Perhaps IOHub should be replaced? Again keep me in the loop. thanks (Now using OSX 10.15.3

Keep in mind that, to my knowledge, macOS 10.13 or above adds a 1 refresh delay to display updates, so if you are planning on doing any gaze contingent type paradigms with the eye tracker, Windows or Linux would be better operating system choices IMO.

I’m not trying to justify any iohub + macOS issues that may exist, just pointing out macOS 10.13+ is not a great choice if you need to update your display as quickly as possible in response to an (eye) event.

Hi Sol,

thanks for the information. Due to other software requirements, I think we will use a Windows 10 machine for the upcoming experiments involving eye-tracking. But your comment adds another reason to avoid the macOS for that purpose. I just wanted to start preparing the code in advance on my Mac and stumbled upon the more general problems with macOS and ioHub. I will give it another try on my Mac once the tracker arrives and keep you posted @Bill_Prinzmetal.

Out of interest: Are there any plans to create a hardware.Mouse class (like the one in ioHub) so that I can fully move away from the event class altogether?

I did some more testing with (hopefully insightful) results:

First, the ioHub also does not work on my private Mac (macOS 10.14.6) with the most recent standalones of PsychoPy3 (2020.1.1 - 2020.1.3). However, and this might be good news, ioHub actually works when the scripts are run with my Python3 installation from the terminal. I used homebrew to install Python3 (v3.7.6_1):

brew install python3

Then, I installed PsychoPy3 via:

pip3 install psychopy

Running the basic ioHub-startup with the code of my original posts now works and I could get all my scripts to run fine when called from the terminal. It is possible that some important modules (?) for ioHub are not included in the current standalone for macOS, but are installed when it is called by pip? I remember a post from @Bill_Prinzmetal suggesting that the “accessibility” module might cause the problems? Or does the Python version matter? The standalone uses Python 3.6.1, right? When called from the terminal on my machine, the code is run by Python 3.7.6. I could test that by “forcing” the PsychoPy3 standalone to use Python 3.7.6, but I am not completely sure how. Changing the shebang to refer to the location of the Python 3.7.6 installation did not change the outcome. Or is it possible the change the Python version that comes with PsychoPy3 in the standalone?

I would be happy to do more testing, but I need some pointing into the appropriate direction.

Best,

Malte

As a sidenote: Trying to install the recent version of PsychoPy3 with homebrew returns the following error:

curl: (22) The requested URL returned error: 404 Not Found
Error: Download failed on Cask 'psychopy' with message: Download failed: https://github.com/psychopy/psychopy/releases/download/2020.2.3/StandalonePsychoPy3-2020.1.3-MacOS.dmg

Is there a typo in “…/download/2020.2.3/…”?

Malte,
That is progress. I tried the various demonstrations that are embedded in the stand alone psychoPy for mouse, keyboard, and eye movements from a mac OS X 10.14.X and only one (I forgot, mouse or keyboard) worked.

To me it means that there is something wrong with dependencies or perhaps security permissions but since it works from the terminal, seems like dependencies.  I gave up but you have given me new hope.  At least this problem is bugging someone and it's not related to the OS X version.  When it does not work on the stand alone, does it stall out and work very very slowly as I described?

Thank you for your help.  I think you made progress.

@Bill_Prinzmetal

Thanks very much for doing these tests and posting your findings. It does sound like some iohub dependency might be missing from the macOS PsychoPy3 standalone. @jon, is this something that could be look into for the next release?

In terms of macOS permissions, iohub does not use the “accessibility ” python package, although it looks interesting. You need to manually set the accessibility settings for whatever apps are launching python, otherwise iohub keyboard and mouse will not be able to generate events on macOS.

So for now to use iohub on macOS please follow @maltemaxmoeller 's instructions to manually install python3 and PsychoPy3 and run the experiment script from the terminal.

Thanks again.

I’ll certainly look into the dependencies. The problem is that on my dev machine the iohub demos work, even running from the app bundle, but maybe it’s finding some other copy of a necessary lib hidden in a local folder. I need to test on a clean machine.

Yes, this should be 2020.1.3. It initially got uploaded with that wrong location and whoever made the homebrew cask (a person? a bot? I’ve no idea) obviously used that initial link

Yes, I’d like to do that at some point but haven’t got there yet. It’s a bit more complicated than the keyboard.

So I’m on OSX High Sierra (10.13.6) because Mojave and Catalina seem to break everything, and I also have iohub crashing from the 2020.1.2 standalone (slightly modified with my patch for the directory bug), but with different error messages that may be more informative. I ran the iohub demo “launchserver.py”, and here’s the complete output:

Welcome to PsychoPy3!
v2020.1.2
## Running: /Applications/PsychoPy3.app/Contents/Resources/lib/python3.6/psychopy/demos/coder/iohub/launchHub.py ##


Running testWithNoKwargs Test:

 ** PRESS A KEY TO CONTINUE.....
2.2037     WARNING     Monitor specification not found. Creating a temporary one...
ioHub Server Process Completed With Code:  0
2020-03-14 11:59:04.974 python[22334:1668649] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to (null)
=============================
Error trying to send data to experiment process:
max_pkt_sz: 32748
reply_data_sz: 10934
pkt_cnt: -1
packet index, byte index: -1-1
Traceback (most recent call last):
  File "/Applications/PsychoPy3.app/Contents/Resources/lib/python3.6/psychopy/iohub/server.py", line 348, in sendResponse
    self.socket.sendto(reply_data, address)
  File "/Applications/PsychoPy3.app/Contents/Resources/lib/python3.6/gevent/_socket3.py", line 433, in sendto
    return _socket.socket.sendto(self._sock, *args)
OSError: [Errno 40] Message too long
----
Traceback (most recent call last):
  File "/Applications/PsychoPy3.app/Contents/Resources/lib/python3.6/psychopy/demos/coder/iohub/launchHub.py", line 158, in <module>
    result = namespace[test]()
  File "/Applications/PsychoPy3.app/Contents/Resources/lib/python3.6/psychopy/demos/coder/iohub/launchHub.py", line 42, in testWithNoKwargs
    io.wait(0.25)
  File "/Applications/PsychoPy3.app/Contents/Resources/lib/python3.6/psychopy/iohub/client/__init__.py", line 556, in wait
    events = self.getEvents()
  File "/Applications/PsychoPy3.app/Contents/Resources/lib/python3.6/psychopy/iohub/client/__init__.py", line 373, in getEvents
    self.allEvents.extend(events)
TypeError: 'int' object is not iterable
##### Experiment ended. #####

So there seem to be two parts to the problem. One is Errno 40 “message too long” which I don’t even know what to say about, the other appears to be a type mismatch error where self.getEvents is returning an int rather than a list. IIRC, that’s what iohub does when something isn’t reading properly (e.g., it returns ints for eye-tracker samples that are blank or when the tracker isn’t recording). So the more interesting piece is probably the “Message too long” error, but I don’t understand the socket system nearly well enough to have a guess at what that means.