From psychopy import event, visual

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. Contribute - pygame wiki
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.

1 Like

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).

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.

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.

Hello, I am receiving the same error (ImportError: Library “c” not found). I have manually installed PsychoPy using Anaconda following the instructions on the website, and have ensured all of the packages are up to date.

The PsychoPy program (that I modified from a program created in Builder) runs fine from the terminal on an iMac, but now wont run on a MacBook Air, instead throwing this error:

$ python PER_practice-test.py
Traceback (most recent call last):
File “/Users/talithaford/anaconda3/envs/psypy3_v2/lib/python3.5/site-packages/pyglet/init.py”, line 378, in getattr
return getattr(self._module, name)
AttributeError: ‘NoneType’ object has no attribute ‘get_default’
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/Users/talithaford/Dropbox/Work/Deakin/Projects/NeuroSPA/TMF/6. Testing/NeuroSPA_PER_task/PER_practice-test.py”, line 15, in
from psychopy import locale_setup, sound, gui, visual, core, data, event, logging, clock
File “/Users/talithaford/anaconda3/envs/psypy3_v2/lib/python3.5/site-packages/psychopy/visual/init.py”, line 26, in
from .text import TextStim
File “/Users/talithaford/anaconda3/envs/psypy3_v2/lib/python3.5/site-packages/psychopy/visual/text.py”, line 29, in
import psychopy.event
File “/Users/talithaford/anaconda3/envs/psypy3_v2/lib/python3.5/site-packages/psychopy/event.py”, line 63, in
from pyglet.window.mouse import LEFT, MIDDLE, RIGHT
File “/Users/talithaford/anaconda3/envs/psypy3_v2/lib/python3.5/site-packages/pyglet/window/init.py”, line 1896, in
gl._create_shadow_window()
File “/Users/talithaford/anaconda3/envs/psypy3_v2/lib/python3.5/site-packages/pyglet/gl/init.py”, line 208, in _create_shadow_window
_shadow_window = Window(width=1, height=1, visible=False)
File “/Users/talithaford/anaconda3/envs/psypy3_v2/lib/python3.5/site-packages/pyglet/window/init.py”, line 501, in init
display = get_platform().get_default_display()
File “/Users/talithaford/anaconda3/envs/psypy3_v2/lib/python3.5/site-packages/pyglet/window/init.py”, line 1845, in get_default_display
return pyglet.canvas.get_display()
File “/Users/talithaford/anaconda3/envs/psypy3_v2/lib/python3.5/site-packages/pyglet/canvas/init.py”, line 77, in get_display
from pyglet.app import displays
File “/Users/talithaford/anaconda3/envs/psypy3_v2/lib/python3.5/site-packages/pyglet/app/init.py”, line 175, in
event_loop = EventLoop()
File “/Users/talithaford/anaconda3/envs/psypy3_v2/lib/python3.5/site-packages/pyglet/app/base.py”, line 119, in init
self.clock = clock.get_default()
File “/Users/talithaford/anaconda3/envs/psypy3_v2/lib/python3.5/site-packages/pyglet/init.py”, line 384, in getattr
import(import_name)
File “/Users/talithaford/anaconda3/envs/psypy3_v2/lib/python3.5/site-packages/pyglet/clock.py”, line 169, in
_c = pyglet.lib.load_library(‘c’)
File “/Users/talithaford/anaconda3/envs/psypy3_v2/lib/python3.5/site-packages/pyglet/lib.py”, line 158, in load_library
raise ImportError(‘Library “%s” not found.’ % names[0])
ImportError: Library “c” not found.

I created a new virtual environment with a clean install as per the instructions and receive the same error (also using iPython). Here are the commands for the package installs:

from __ future__ import absolute_import, division
from psychopy import locale_setup, sound, gui, visual, core, data, event, logging, clock
from psychopy.constants import (NOT_STARTED, STARTED, PLAYING, PAUSED, STOPPED, FINISHED, PRESSED, RELEASED, FOREVER)
import numpy as np # whole numpy lib is available, prepend ‘np.’
from numpy import (sin, cos, tan, log, log10, pi, average, sqrt, std, deg2rad, rad2deg, linspace, asarray)
from numpy.random import random, randint, normal, shuffle
import os # handy system and path functions
import sys # to get file system encoding
from psychopy.hardware import keyboard

Note that the fix by ezimokhai (importing locale_setup) has already been implemented.
Any advice would be greatly appreciated. Thank you.