This is less a problem and more a request for information. Version 2020.1 added this fancy new run window, which is great, but it seems to have strange behavior w/r/t what it sets as the active directory when running a python script. For my purposes in particular (i.e., PyHab), I have scripts that look for a few files in the directory in which the script is saved. However, this is not what PsychoPy recognizes as the working directory (at least on Mac). os.getcwd() instead returns “/Applications/PsychoPy3.app/Contents/Resources”
So 1) why this change, and is it necessary for running a single script? Put bluntly, can we go back to the pre-2020.1 behavior or is there a clear advantage to this new approach?
2) If not, I can get the working directory back where it needs to go with
os.path.dirname(os.path.realpath(__file__)), but is this the best way?
My main concerns have to do with replicability across labs - if you want to share a custom script across labs, and it relies on external files, then this is going to require either updating the path manually in every new lab, or including some code to update it automatically. It also seems bad for backward compatibility.
I’m running into this problem too, with the latest PsychoPy3 version running on Windows. Do you know if there’s a way for me to incorporate your fix in a Windows environment before PsychoPy rolls it into their releases? I don’t appear to have the script you modified. Thanks!
There is a temporary fix you can apply to just the script that is having the problem. At the top of your script, put:
If you want to incorporate the change to PsychoPy itself before the next version rolls out, you can download this file:
and then on Windows go to Program Files\PsychoPy3\Lib\site-packages\psychopy\app\runner\ and replace the file of the same name.
Thanks for the follow-up! Yeah, the Windows install does not appear to have the “runner” subdirectory or any file named scriptProcess.py. I was thinking there might be an analogous file with a different name for Windows, but I didn’t want to just go replacing the wrong file! I’ll just use the temp fix meanwhile. Thanks again!
Update: As of 2020.1.3 this is fixed.
I’m running into this issue on Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 26 2016, 12:10:39). I need to use PsychoPy2 because PsychoPy3 does not work for collecting data from a remote keyboard, which is what I need to do.
I am trying to accomplish a similar goal to the one first introduced in this thread. I am trying to find files relative to the directory in which the script is saved. I am on a Mac.
The following code:
Also returns: ‘/Applications/PsychoPy2.app/Contents/Resources’
Is there a suggested way to resolve this without updating PsychoPy itself?