PsychoPy and the Tobii Python SDK

While the Tobii SDK does not directly support PsychoPy, PsychoPy has example code that should work with the Tobii trackers (and several other eye trackers). However, getting the example code to run is not always easy as there can be some problems that can be difficult to troubleshoot if you aren’t familiar with Python or PsychoPy. [Edit: Please note all of this advice pertains to PsychoPy 1.81.03  and may not work with later versions of PsychoPy].

With my coworker Burcin Dede, we have been documenting some common problems with getting psychopy’s demo code to run with the Tobii tracker and some important notes we have made are listed below: You can find a code example within the PsychoPy GUI if you look at the ‘demos’ drop-down menu and look within the ioHub section: Demos>ioHub>gCursor.

In fact PsychoPy has a huge amount of demos that are well worth examining as many techniques for psychophysics experiments are shown off and can save a lot of work! If you have any problems running the demo, you can double check following things:

1. Make sure that the SDK is properly setup with pyGTK and the python path is correctly set (SDK developer guide pg. 62)

2. Make sure that sample codes in the Tobii SDK can run in python, these examples are located in: C:\(sdk install location)\TobiiAnalyticsSDK-3.0.83-Win\tobii-analytics-sdk-3.0.83-win-Win32\Python27\Samples

3. You may need to try running PsychoPy as an admin

4. Be sure to comment out the portion of the config.yaml file that references any trackers that aren’t Tobii and to uncomment any sections that refer to the Tobii tracker.

5. A configuration file is written by default to specify a non-Tobii eye tracker so must change it. The iohub.config.yaml file and the source code for the demo can be found in your psychopy install directory (it will look something like): C:\(psychopy install location)\PsychoPy2\Lib\site-packages\PsychoPy-1.80.03-py2.7.egg\psychopy-1.80.03\demos\coder\iohub\eyetracking\gcCursor

6. Download and install the latest version of the avbin library

7. If you have more than one Tobii tracker, make sure to only have the one you are using plugged in. By default the psychopy program requests the name of the first tracker connected and will have unpredictable results if it sees multiple trackers. You have to manually edit the program if you want to use your specific tracker id.

**Update Sept 9 2016**

For those of you who prefer a different IDE, I’ve found Python(x,y) to be a pretty good matlab (my usual platform) replacement, it’s a package that contains many useful libraries (ie. numpy, matplotlib, scipy, and many more) and does a lot of the tedious housekeeping for you in one install, along with installing several useful python dev apps. Python(x,y) comes bundled with Spyder which is a very nice IDE. However, if you are trying to run code from PsychoPy using Spyder it’s not obvious at first how to make this happen (i.e. how do you add the right directories to the environment). Fortunately, Jonas Lindelov has a nice blog on several aspects of python including this very issue. I’ve reprinted part of his solution below (note this gui solution may cause issues with ipython console, library conflict, if so try the import version instead):

On windows, Spyder is pre-packaged in the python(x,y) package among others. Install that. If you use Windows, you need to make Spyder “aware” of PsychoPy by doing the following:

  1. Open Spyder –> Tools –> PYTHONPATH manager
  2. Add the following two paths (psychopy usually installs to C:\Program Files (x86)\PsychoPy2 on Windows) and do NOT click “synchronize”.
  3. Now open Spyder and you should be able to run the following small script without errors:

Now go to “Tools –> Preferences –> Run”, and tick “Execute in a dedicated Python interpreter” to make it easy to re-run the experiment without getting errors due to python being shut down when the psychopy module is unloaded.

Import version code you can put at top of your scripts if you end up with ipython conflicts like I did:

import sys