psychopy.org | Reference | Downloads | Github

From psychopy import event, visual

python2
#1

I am trying to use psychopy for a user study, I have tried to run the standalone psychopy which works fine however I can not use the standalone application as i use python to run a separate device hence the need of running everything within python.
I have the latest psychopy version 3.10 installed
System MacOS High Sierra

Below is the error I get when i try to run my script, I have ran each import individually so that I can copy the error message.

from psychopy import event
Traceback (most recent call last):
File “”, line 1, in
File “/usr/local/lib/python2.7/site-packages/psychopy/event.py”, line 63, in
from pyglet.window.mouse import LEFT, MIDDLE, RIGHT
File “/usr/local/lib/python2.7/site-packages/pyglet/window/init.py”, line 1896, in
gl._create_shadow_window()
File “/usr/local/lib/python2.7/site-packages/pyglet/gl/init.py”, line 208, in _create_shadow_window
_shadow_window = Window(width=1, height=1, visible=False)
File “/usr/local/lib/python2.7/site-packages/pyglet/window/init.py”, line 497, in init
EventDispatcher.init(self)
TypeError: expected string or buffer

from psychopy import visual
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File “”, line 1, in
File “/usr/local/lib/python2.7/site-packages/psychopy/visual/init.py”, line 26, in
from .text import TextStim
File “/usr/local/lib/python2.7/site-packages/psychopy/visual/text.py”, line 29, in
import psychopy.event
File “/usr/local/lib/python2.7/site-packages/psychopy/event.py”, line 63, in
from pyglet.window.mouse import LEFT, MIDDLE, RIGHT
File “/usr/local/lib/python2.7/site-packages/pyglet/window/init.py”, line 1896, in
gl._create_shadow_window()
File “/usr/local/lib/python2.7/site-packages/pyglet/gl/init.py”, line 208, in _create_shadow_window
_shadow_window = Window(width=1, height=1, visible=False)
File “/usr/local/lib/python2.7/site-packages/pyglet/window/init.py”, line 501, in init
display = get_platform().get_default_display()
File “/usr/local/lib/python2.7/site-packages/pyglet/window/init.py”, line 1845, in get_default_display
return pyglet.canvas.get_display()
File “/usr/local/lib/python2.7/site-packages/pyglet/canvas/init.py”, line 77, in get_display
from pyglet.app import displays
File “/usr/local/lib/python2.7/site-packages/pyglet/app/init.py”, line 175, in
event_loop = EventLoop()
File “/usr/local/lib/python2.7/site-packages/pyglet/app/base.py”, line 119, in init
self.clock = clock.get_default()
File “/usr/local/lib/python2.7/site-packages/pyglet/init.py”, line 384, in getattr
import(import_name)
File “/usr/local/lib/python2.7/site-packages/pyglet/clock.py”, line 169, in
_c = pyglet.lib.load_library(‘c’)
File “/usr/local/lib/python2.7/site-packages/pyglet/lib.py”, line 158, in load_library
raise ImportError(‘Library “%s” not found.’ % names[0])
ImportError: Library “c” not found.

I have spent time searching for some explanation for how to fix the error and am yet to get some help. Any indication as to why this is will be very much appreciated. The above error is only generated when i run my script from the terminal with python 2. with python 3.7 the error message is that there is no module named psychopy.

#2

It’s probably best to work in Python 3 to future-proof yourself. You’ll need to install PsychoPy and its dependencies into your Python 3 environment though (as this error suggests).

#3

Hi Micheal,
Thanks for the response but I spent yesterday doing just that and the same error as before is what I get and I was hoping that I will get some insight into the error for python 2 as well and not just python 3. However when I try to run the script via spyder the error no module name psychopy install is returned.

#4

Just for those who might be having similar issue as above, I found a work around by using the standalone version to create study and discovered that the error i was getting was as a result some incomplete import from psychopy (from psychopy import sound, gui, visual, core, data, event, logging, clock).

Revised import is from psychopy import locale_setup, sound, gui, visual, core, data, event, logging, clock.