How to install PsychoPy 2022.1.4 on Ubuntu 22.04 using virtualenv

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

Installing 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 pocketsphinx
  • libgtk-3-dev and libwebkit2gtk-4.0-dev are needed to build wxPython
  • 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

cd Environments

And activate the environment we just created so we can install PsychoPy and its dependencies inside of it.

source psychopy-py38/bin/activate

If that works, you’ll see that (psychopy-py38) will appear before your prompt. In my case, my prompt reads: (psychopy-py38) flavio@flavio-notebook:~/Environments$

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

Upgrade pip

pip install pip -U

Now, we can install psychopy using pip

pip install psychopy==2022.1.4

Install wxPython - this takes a long time to compile (around 30 minutes). But, look at the bright side: we only have to do it once :wink:

pip install wxpython

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

source Environments/psychopy-py38/bin/activate

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.

That’s it :slight_smile:

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).