Visual psychophysics with Python


I rediscovered the VisionEgg library which is a powerful Python package for building visual and auditory psychophysical experiments, among others. More generally, this can be viewed as a wrapper for Pygame.

When I started my PhD, I was used to the Psychophysics toolbox for MATLAB (but I haven’t any Mac at that time) and it was pretty cool. I learned 3 or 4 years ago that most of my visual stimulations could be made thanks to Pygame but this is the end of the story: I never had to program any other experiment since then. Googling about the Psychtoolbox, I learned that it is now compatible with Octave (a great news since most of my old Matlab scripts never ran on Octave!), but see the aforementioned wiki.

Setup is quite straightforward, although compilation of gl_qt.c failed. Most of the demo scripts are running.

A note about PyQt

To get a working Qt binding for Python, you will need the PyQt4 which also depends on sip. Both packages can be downloaded from Note, however, that they must be compiled as 32 bits since no 64 bits Qt is actually available (it is planned for version 4.7).

$ python —arch i386
$ make
$ sudo make install
$ file /System/Library/Frameworks/Python.framework/Versions/2.6/bin/sip
/System/Library/Frameworks/Python.framework/Versions/2.6/bin/sip: Mach-O executable i386

For PyQt, just use

$ python —use-arch i386
$ make

It’s about 10’ of compilation where a warning is issued at each step, Support for this version of Mac OS X is still preliminary. You should end up with something like

g++ -headerpad_max_install_names -arch i386 -single_module \
-dynamiclib -o libpythonplugin.dylib pluginloader.o \
moc_pluginloader.o  -F/Library/Frameworks -L/Library/Frameworks \
-framework Python -framework QtDesigner -framework QtScript \
-framework QtXml -framework QtGui -framework Carbon \
-framework AppKit -framework QtCore -lz -lm \
-framework ApplicationServices

As can be seen, several tools are built at once (QtGui, QtHelp, QtMultimedia, QtNetwork, QtOpenGL, QtScript, QtScriptTools, QtSql, QtSvg, QtTest, QtWebKit, QtXml, QtXmlPatterns, phonon, QtAssistant, QtDesigner), all as Framework. After make install, many files will be installed in Python system-wide directories, as well as the /Developer directory (e.g. libpythonplugin.dylib).

import sys
from PyQt4 import QtGui
app = QtGui.QApplication(sys.argv)
btn = QtGui.QPushButton(“Installation seems ok!”)


Articles with the same tag(s):

Yet another gray theme for R base graphics
Light Table and interactive live coding
Python for interactive scientific data visualization
Bar charts of counts or frequencies in Stata
Emacs auto-completion for Python
Interactive data visualization with cranvas
Interacting with Weka from Jython
Easy creation of videos with R
IPython 0.11, the new killer app