Here, I’ll show how to install PsychoPy in a virtual environment, so we can use python 3.8 instead of python 3.10 (which comes with Ubuntu 22.04), but in a “sandboxed” way, without touching python’s system install.
First, let’s install
virtualenv, which will also install a bunch of other packages we’ll need along the way (to compile
wxPython, for instance).
sudo apt install virtualenv
To install python 3.8 we’ll need to install the
deadsnakes ppa repository.
sudo add-apt-repository ppa:deadsnakes/ppa
python3.8-dev package installs also some dependencies we’ll need, but not all of them. Other packages are needed for different purposes that I’ll list below for documentation.
- swig, libpulse-dev and libasound2-dev are needed to install
- libgtk-3-dev and libwebkit2gtk-4.0-dev are needed to build
- git is required to save .psyexp file using Builder.
- libxcb-xinerama0 libegl1-mesa are required to solve this error that prevents Builder from running experiments.
sudo apt install python3.8-dev swig libpulse-dev libasound2-dev libgtk-3-dev git libwebkit2gtk-4.0-dev libxcb-xinerama0 libegl1-mesa
Now, let’s create the virtual environment, with python 3.8, inside a directory I’ll call “Environments” - I like the ideia of organizing environments inside a single directory, so I don’t have many folders in my Home directory. However, feel free to change this as you like.
virtualenv --python /usr/bin/python3.8 ~/Environments/psychopy-py38
Now, go inside your Environments directory
And activate the environment we just created so we can install PsychoPy and its dependencies inside of it.
If that works, you’ll see that
(psychopy-py38) will appear before your prompt. In my case, my prompt reads:
We have to reinstall
python3.8-distutils to get
pip to work inside the virtual environment - because of a bug reported here.
sudo apt install --reinstall python3.8-distutils
pip install pip -U
attrdict, which will be required latter on, to keep installing psychopy.
pip install attrdict
Now, we can install psychopy using
pip install psychopy==2022.2.4
wxPython will be compiled during the installation - this takes a long time to compile (around 30 minutes). But, look at the bright side: we only have to do it once
Now you should be able to run PsychoPy.
But let’s go back to the global environment first, so I can show you the two lines of code needed to start PsychoPy:
To run PsychoPy Builder we first need to activate the virtual environment
And then run PsychoPy Builder
psychopy --builder &
When you run it for the first time, a popup will tell you that
psychtoolbox needs further configuration. The same steps are described here in case you miss it and want to find them again.
It is also recommended that you go to Properties → Audio and change “Audio library” to “ptb” (i.e. to use psychtoolbox).
Login to pavlovia from Builder is not working. It’s not a new issue, actually - there’s a thread on this problem here. Therefore, I’ve been using gitg to sync my projects with gitlab / pavlovia. If you want to know more about it, leave a comment here.
Builder still crashes when typing a dollar sign into a text component. It is an old bug that came back (it’s a tough bug…). To get rid of it, follow this instructions.
PS: I’d like to thank @arnon_weinberg and @kxKkPbRawwdwEu for their comments on my previous how to, which led to this more polished one (I’m hoping).
PS2: I’ve updated the how-to, since the installation process changed a bit using pip to get the current version of PsychoPy (2022.2.4).