I’m using the raspberry pi os with psychopy 1.2 and python 3.9.6
Basically I’m trying to use Psychopy on my paspberry pi 4 but it’s not working, I installed it using pip with the “–no-deps” flag, because some dependencies would not want to download, I then installed all the necessary packages manually. I can’t open the GUI, unless there’s a way I didn’t try, and when I try to run a script, that I generated on my other computer, using python, the code works until it gets to the line “win = visualWindow(…)” if I run the code with the terminal, I get a “segmentation fault” and if I run it with Thonny, the error message is : “Backend terminated or disconnected.”. I don’t really need the GUI, since I only plan to use the pi to run the code and not make it.
here is the code I’m trying to run:
#!/usr/bin/env python
-- coding: utf-8 --
from psychopy import locale_setup
from psychopy import prefs
from psychopy import sound, gui, visual, core, data, event, logging, clock, colors, layout
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, choice as randchoice
import os # handy system and path functions
import sys # to get file system encoding
import psychopy.iohub as io
from psychopy.hardware import keyboard
Ensure that relative paths start from the same directory as this script
_thisDir = os.path.dirname(os.path.abspath(file))
os.chdir(_thisDir)
Store info about the experiment session
psychopyVersion = ‘2022.1.2’
expName = ‘untitled’ # from the Builder filename that created this script
expInfo = {‘participant’: ‘’, ‘session’: ‘001’}
dlg = gui.DlgFromDict(dictionary=expInfo, sortKeys=False, title=expName)
if dlg.OK == False:
core.quit() # user pressed cancel
expInfo[‘date’] = data.getDateStr() # add a simple timestamp
expInfo[‘expName’] = expName
expInfo[‘psychopyVersion’] = psychopyVersion
Data file name stem = absolute path + name; later add .psyexp, .csv, .log, etc
filename = thisDir + os.sep + u’data/%s%s_%s’ % (expInfo[‘participant’], expName, expInfo[‘date’])
An ExperimentHandler isn’t essential but helps with data saving
thisExp = data.ExperimentHandler(name=expName, version=’’,
extraInfo=expInfo, runtimeInfo=None,
originPath='C:\\Users\\jacov\\Desktop\\untitled_lastrun.py',
savePickle=True, saveWideText=True,
dataFileName=filename)
save a log file for detail verbose info
logFile = logging.LogFile(filename+’.log’, level=logging.EXP)
logging.console.setLevel(logging.WARNING) # this outputs to the screen, not a file
endExpNow = False # flag for ‘escape’ or other condition => quit the exp
frameTolerance = 0.001 # how close to onset before ‘same’ frame
Start Code - component code to be run after the window creation
Setup the Window
win = visual.Window(
size=(1024, 768), fullscr=True, screen=0,
winType='pyglet', allowGUI=False, allowStencil=False,
monitor='testMonitor', color=[0,0,0], colorSpace='rgb',
blendMode='avg', useFBO=True,
units='height')
store frame rate of monitor if we can measure it
expInfo[‘frameRate’] = win.getActualFrameRate()
if expInfo[‘frameRate’] != None:
frameDur = 1.0 / round(expInfo['frameRate'])
else:
frameDur = 1.0 / 60.0 # could not measure, so guess
Setup ioHub
ioConfig = {}
Setup iohub keyboard
ioConfig[‘Keyboard’] = dict(use_keymap=‘psychopy’)
ioSession = ‘1’
if ‘session’ in expInfo:
ioSession = str(expInfo['session'])
ioServer = io.launchHubServer(window=win, **ioConfig)
eyetracker = None
create a default keyboard (e.g. to check for escape)
defaultKeyboard = keyboard.Keyboard(backend=‘iohub’)
Initialize components for Routine “trial”
trialClock = core.Clock()
text = visual.TextStim(win=win, name=‘text’,
text='Any text\n\nincluding line breaks',
font='Open Sans',
pos=(0, 0), height=0.05, wrapWidth=None, ori=0.0,
color='white', colorSpace='rgb', opacity=None,
languageStyle='LTR',
depth=0.0);
Create some handy timers
globalClock = core.Clock() # to track the time since experiment started
routineTimer = core.CountdownTimer() # to track time remaining of each (non-slip) routine
------Prepare to start Routine “trial”-------
continueRoutine = True
routineTimer.add(1.000000)
update component parameters for each repeat
keep track of which components have finished
trialComponents = [text]
for thisComponent in trialComponents:
thisComponent.tStart = None
thisComponent.tStop = None
thisComponent.tStartRefresh = None
thisComponent.tStopRefresh = None
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
reset timers
t = 0
_timeToFirstFrame = win.getFutureFlipTime(clock=“now”)
trialClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
frameN = -1
-------Run Routine “trial”-------
while continueRoutine and routineTimer.getTime() > 0:
# get current time
t = trialClock.getTime()
tThisFlip = win.getFutureFlipTime(clock=trialClock)
tThisFlipGlobal = win.getFutureFlipTime(clock=None)
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *text* updates
if text.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
text.frameNStart = frameN # exact frame index
text.tStart = t # local t and not account for scr refresh
text.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(text, 'tStartRefresh') # time at next scr refresh
text.setAutoDraw(True)
if text.status == STARTED:
# is it time to stop? (based on global clock, using actual start)
if tThisFlipGlobal > text.tStartRefresh + 1.0-frameTolerance:
# keep track of stop time/frame for later
text.tStop = t # not accounting for scr refresh
text.frameNStop = frameN # exact frame index
win.timeOnFlip(text, 'tStopRefresh') # time at next scr refresh
text.setAutoDraw(False)
# check for quit (typically the Esc key)
if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
core.quit()
# check if all components have finished
if not continueRoutine: # a component has requested a forced-end of Routine
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in trialComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
-------Ending Routine “trial”-------
for thisComponent in trialComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
thisExp.addData(‘text.started’, text.tStartRefresh)
thisExp.addData(‘text.stopped’, text.tStopRefresh)
Flip one final time so any remaining win.callOnFlip()
and win.timeOnFlip() tasks get executed before quitting
win.flip()
these shouldn’t be strictly necessary (should auto-save)
thisExp.saveAsWideText(filename+’.csv’, delim=‘auto’)
thisExp.saveAsPickle(filename)
logging.flush()
make sure everything is closed down
if eyetracker:
eyetracker.setConnectionState(False)
thisExp.abort() # or data files will save again on exit
win.close()
core.quit()