| Reference | Downloads | Github

Mac: Importing psychopy gui crashes script


The script below crashes when running on my Mac:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from psychopy import visual, gui

Just importing visual or gui causes no issues, but both causes the following crash:

2018-03-12 14:50:19.450 python[9926:211347] -[NSApplication transformToForegroundApplication]: unrecognized selector sent to instance 0x7feb9a5a6c20
2018-03-12 14:50:19.513 python[9926:211347] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSApplication transformToForegroundApplication]: unrecognized selector sent to instance 0x7feb9a5a6c20'
*** First throw call stack:
	0   CoreFoundation                      0x00007fff4018c33b __exceptionPreprocess + 171
libc++abi.dylib: terminating with uncaught exception of type NSException
Abort trap: 6

I was wondering if anyone had come across this, and has a solution? I’m running on MacOS 10.13.3, Python 2.7.14 with the following packages installed:
asn1crypto (0.24.0)
backports.functools-lru-cache (1.5)
certifi (2018.1.18)
cffi (1.11.5)
chardet (3.0.4)
configobj (5.0.6)
cryptography (2.1.4)
cycler (0.10.0)
decorator (4.0.11)
enum34 (1.1.6)
et-xmlfile (1.0.1)
future (0.16.0)
gevent (1.2.2)
greenlet (0.4.13)
idna (2.6)
imageio (2.1.2)
ipaddress (1.0.19)
jdcal (1.3)
json-tricks (3.11.3)
kiwisolver (1.0.1)
lxml (4.1.1)
matplotlib (2.2.0)
moviepy (
msgpack-python (0.5.6)
numexpr (2.6.4)
numpy (1.14.1)
opencv-python (
openpyxl (2.5.1)
pandas (0.22.0)
Pillow (5.0.0)
pip (9.0.1)
psutil (5.4.3)
PsychoPy (1.85.6)
pycparser (2.18)
pygame (1.9.3)
pyglet (1.3.1)
pyobjc-core (4.1)
pyobjc-framework-Cocoa (4.1)
pyobjc-framework-Quartz (4.1)
PyOpenGL (3.1.0)
pyOpenSSL (17.5.0)
pyosf (1.0.5)
pyparallel (0.2.2)
pyparsing (2.2.0)
pyserial (3.4)
python-bidi (0.4.0)
python-dateutil (2.7.0)
pytz (2018.3)
PyYAML (3.12)
requests (2.18.4)
scipy (1.0.0)
setuptools (38.5.2)
six (1.11.0)
sounddevice (0.3.10)
SoundFile (0.10.1)
subprocess32 (3.2.7)
tables (3.4.2)
tqdm (4.11.2)
urllib3 (1.22)
wheel (0.30.0)
wxPython (4.0.1)
xlrd (1.1.0)

I’m looking into a script built with PsychoPy2 Experiment Builder (v1.79.60) and I am trying to figure out why it won’t run.



Not totally sure what’s up with this, but I have a few things you could try.

  1. Are you using the standalone installer or a pip install? If you are using the standalone installer it comes with its own version of Python, so your installed packages won’t matter. It may be easiest to grab an earlier standalone, like 1.79 or 1.8, from here:

  2. GUI, at least as of now, uses pyQt, which isn’t listed. There are bits of pyQt4 and pyQt5, but as I recall 4 is the one that psychopy.gui uses.

  3. I kind of doubt this is it, but in system preferences, under security settings > accessibility, make sure PsychoPy is listed as a program that is allowed to control your computer.


Thanks for the response. I’m running the script from within a virtualenv, so I can get an idea of which packages are needed. Interestingly I copied PyQt4 into the virtualenv, and the crash changed from the above to:

  from psychopy import visual, gui
  File "~/TOM/TOM/lib/python2.7/site-packages/psychopy/gui/", line 33, in <module>
    from .qtgui import *
  File "~/TOM/TOM/lib/python2.7/site-packages/psychopy/gui/", line 19, in <module>
    from PyQt5 import QtWidgets
ImportError: No module named PyQt5

I’m going to try copying PyQt5 in and see how that changes things.


Ah, the PyQt5 error was caused by the PyQt4 dependency sip being missing


Adding sip in just seems to have returned the program to it’s original problem. This seems to me to mean that the issue is independent of PyQt. Having had a quick tinker with the psychopy the issue occurs if PyQt4 or wxPython are used. I will try running the script through gdb and see what that turns up.


I’m not exactly sure what the problem is but we didn’t have compatibility with wx4 in PsychoPy 1.85.x so that could be part of your problem. That has been added (and PsychoPy should now install all its dependencies except for pyo) if you use the current repository version (or psychopy=1.90.dev3 test release)


I’ve been trying the 1.80.86 standalone release, and am getting stuck with the error ValueError: dylib libevent.dylib could not be found. I assume this is because I use the Mac Ports package manager and as such most of my libs are in /opt/local/, however adding the line search_path.append('/opt/local/lib/') to pyglet/ is having no effect. Any ideas what might get it working?