Using psychopy standalone on mac with visual studio code

Hi,

I installed Standalone Psychopy On a Mac computer and I use VS Code as a code editor. How can I add the standalone psychopy as a python interpreter to vs code?

Trying to add Applications/PsychoPy.app/Contents/MacOS/python did not work.

1 Like

The standalone isn’t going to work for you for this purpose - you’ll need to install the PsychoPy library and its many dependencies into an environment with a regular Python interpreter. It’s best to create a separate environment just for that (eg with Conda), so that you don’t break your everyday Python installation (and vice versa). I imagine that VSCode is like most IDEs and will allow you to simply flick between the Python interpreters in each environment.

The disadvantage of not using the standalone is that you have to manage all of the third-party dependencies yourself, and that can cause a few hiccups along the way.

Probably best to follow the instructions for the developer install of PsychoPy - that way you can use gut to control the PsychoPy version (eg to keep consistent with the standalone app that you’ll likely use when running the actual experiment).

https://psychopy.org/developers/

There’s a workshop coming up next week for new developers I think - that would cover everything you need to know and more about getting set up.

Sign-ups for the free workshop are here on Eventbrite: Contributing to PsychoPy Workshop Tickets, Wed. & Fri., 26 & 28 April 2023 from 2-5 pm, UK Time.

Hi,

I find this a bit strange. If standalone PsychoPy is installed on my machine, with the appropriate python version and all batteries included (1.2 GB disk space), and apparently uses its own virtual environment, why can’t I tap into (activate) that virtual environment from outside, e.g., from VS Code? Is it a protection issue, i.e., I should not be able to install additional software into that environment, or even worse replace parts?

2 Likes

I also don’t understand this, and thought that copying the files out would fix it, but no dice, it would be interesting to find out why because I’m having a lot of trouble overcoming the dependencies issue doing things the conventional way.

PsychoPy isn’t using a “virtual environment”. It’s using a packaged version of Python designed to work as an application (using py2app). There is no ‘activating’ that virtual environment. If you want to run that python then you have to call the full path to that python

When I use VS Code and set it to use /Applications/PsychoPy.app/Contents/MacOS/python as the interpreter, it works as expected.

1 Like

Notably, I’m selecting the “Enter interpreter path…” option here, as below. Are you doing something else?

Nice, thanks!

Back then, this is what I was trying as well but it did not work. I somehow solved this issue but I don’t remember how. I may have installed it using anaconda instead of the installer. But I remember that when I did it using anaconda the installation was getting stuck at some point as well.

Conda has certainly had issues before with some libs (like hdf5 and wxpython) and I don’t have time to battle with it.

But maybe something changed about the way that the py2app packages the python executable in the bundle that means it now “just works”. I mean that’s my experience, but not working for @AlexHolcombe :thinking:

My feeling is that this could be due to your MacOS version. What is your MacOS version? Maybe Apple has some security precaution to prevent malicious users from running Python code from an app.

If it doesn’t work using Jon’s method, and conda gets stuck using the anaconda install method (which it did for me) you could use conda just as a virtual environment manager, create a conda environment (note that on a Mac you need python 3.8) with
conda create python=3.8 -n psychopy
activate the environment using
conda activate psychopy
and then use pip to install psychopy into that environment.
pip install psychopy
That worked for me, and the environment can be used from VS Code,

That possibility now seems to have been ruled out by my attempts documented here: Installing Psychopy to run with an external editor - #4 by AlexHolcombe

Yes, that’s what I’m doing, but have also tried it outside VSCode, as we now discuss at the other thread :slight_smile: Installing Psychopy to run with an external editor - #4 by AlexHolcombe