Installing Psychopy to run with an external editor

Rather than use the Standalone Psychopy IDE, I would like my students to have access to Github Copilot or other AIs, which require an IDE like VSCode or JetBrains.

So we have tried to install python3.8 and psychopy via pip and via homebrew, but on some computers we run into dependency problems (e.g. HDF5, lzo, other libraries, for which I’ve tried StackOverflow fix suggestions but they haven’t always worked) that I haven’t succeeded in resolving.

I’m thinking another route would be to actually use the contents of the Standalone PsychoPy app, which has its own version of python, and all dependencies, right? That way, we wouldn’t have to navigate all the different dependency issues with brew and pip, and the instructions to do this could be much simpler.

So, I tried to point VSCode at the Python interpreter inside PsychoPy, /Applications/PsychoPy.app/Contents/Frameworks/Python.framework/Versions/3.8/Python, but it didn’t work. At first it complained that “Permission denied” which I think is probably because it’s inside of an App and so you don’t have permission to run it, but then even after I copied all the contents outside into a separate directory, I get a different error:

~/Documents/softwareStatsEquipment/psychopy/copiedOutOfPsychoPyApp/Contents/Frameworks/Python.framework/Versions/3.8/Python ~/.vscode/extensions/ms-python.python-2024.2.1/pythonFiles/create_venv.py --git-ignore
2024-03-11 13:38:26.541 [info] cwd: .
2024-03-11 13:38:26.542 [error] Error while running venv creation script:  Error: spawn /Users/alex/Documents/softwareStatsEquipment/psychopy/copiedOutOfPsychoPyApp/Contents/Frameworks/Python.framework/Versions/3.8/Python EACCES
    at Process.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:476:16)
    at processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -13,
  code: 'EACCES',
  syscall: 'spawn /Users/alex/Documents/softwareStatsEquipment/psychopy/copiedOutOfPsychoPyApp/Contents/Frameworks/Python.framework/Versions/3.8/Python',
  path: '/Users/alex/Documents/softwareStatsEquipment/psychopy/copiedOutOfPsychoPyApp/Contents/Frameworks/Python.framework/Versions/3.8/Python',
  spawnargs: [
    '/Users/alex/.vscode/extensions/ms-python.python-2024.2.1/pythonFiles/create_venv.py',
    '--git-ignore'
  ]
}
2024-03-11 13:38:26.542 [error] Error: spawn /Users/alex/Documents/softwareStatsEquipment/psychopy/copiedOutOfPsychoPyApp/Contents/Frameworks/Python.framework/Versions/3.8/Python EACCES
    at Process.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:476:16)
    at processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -13,
  code: 'EACCES',
  syscall: 'spawn /Users/alex/Documents/softwareStatsEquipment/psychopy/copiedOutOfPsychoPyApp/Contents/Frameworks/Python.framework/Versions/3.8/Python',
  path: '/Users/alex/Documents/softwareStatsEquipment/psychopy/copiedOutOfPsychoPyApp/Contents/Frameworks/Python.framework/Versions/3.8/Python',
  spawnargs: [
    '/Users/alex/.vscode/extensions/ms-python.python-2024.2.1/pythonFiles/create_venv.py',
    '--git-ignore'
  ]

I see now that someone else has tried to do this, but not included the step of copying the files out of the PsychoPy app. Someone responded to say it was impossible, but it’s not clear if they are referring to even when copying it out of the app, are the files in the app compiled in some way or something so they can’t be used this way? Is there no way to capitalize on the Standalone Psychopy having the libraries that are needed?

See also here: How do I get PsychoPy working in PyCharm on mac?

Bottom line is that there is some weirdness about how the standalone is put together that makes this tricky to implement, and getting it working for a class of students will probably require a lot of idiosyncratic troubleshooting. That said, if you can figure out a consistent recipe for doing it, please share!

I don’t know. I just tried this on a mac and it worked fine. :man_shrugging: I could happily run/debug using /Applications/PsychoPy.app/Contents/MacOS/python

Then again, I was just trying to run the file whereas it looks like you’re trying to spawn a new environment? What exactly are you doing?

Thanks Jon, we’ve tried it on 2 different Macbooks here now and get the below error message when trying to simply invoke /Applications/PsychoPy.app/Contents/MacOS/python from Terminal.app: alex@aholcombes-mbp ~ % /Applications/PsychoPy.app/Contents/MacOS/python yields:

Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Python path configuration:
  PYTHONHOME = (not set)
  PYTHONPATH = (not set)
  program name = '/Applications/PsychoPy.app/Contents/MacOS/python'
  isolated = 0
  environment = 1
  user site = 1
  import site = 1
  sys._base_executable = '/Applications/PsychoPy.app/Contents/MacOS/python'
  sys.base_prefix = '/Library/Frameworks/Python.framework/Versions/3.8'
  sys.base_exec_prefix = '/Library/Frameworks/Python.framework/Versions/3.8'
  sys.executable = '/Applications/PsychoPy.app/Contents/MacOS/python'
  sys.prefix = '/Library/Frameworks/Python.framework/Versions/3.8'
  sys.exec_prefix = '/Library/Frameworks/Python.framework/Versions/3.8'
  sys.path = [
    '/Library/Frameworks/Python.framework/Versions/3.8/lib/python38.zip',
    '/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8',
    '/Library/Frameworks/Python.framework/Versions/3.8/lib/lib-dynload',
  ]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

Current thread 0x0000000200e1b280 (most recent call first):
<no Python frame>

From all the references to prefix, it looks even these error messages should have an error message in them, because presumably prefix is meant to be something substantive? Get basically the same error when I point VSCode at this as the interpreter. About the possibility of the operating system somehow trying to stop me to use the contents of an App, I copied all the contents into a normal directory structure, and tried to run python there, but get exactly the same error message. I don’t know, it’s possible you sharing whether your PYTHONHOME and PYTHONPATH environment variables could help me.