How to install PsychoPy 2022.2.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

Install attrdict, which will be required latter on, to keep installing psychopy.

pip install attrdict

Now, we can install psychopy using pip

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 :wink:

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:

deactivate

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.

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.

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

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

7 Likes

Nicely done, thank you for compiling these instructions.

I haven’t used virtualenv before - does it have any advantage over python -m venv in this particular case? It’s not a huge difference but, I suspect, the installation steps could be reduced by using “/usr/bin/python3.8 -m venv ~/Environments/psychopy-py38”.

Also, I haven’t had any problems with pip in venvs; maybe because I use pyenv and it takes care of it? Not sure. After creating & activating the new venv, I just run “python -m pip install -U pip setuptools” and that usually works.

Starting from a clean 22.04.1LTS, I also had to apt install python3.8=tk and pip install attrdict.
Still having trouble with playing movies with an experiment made from builder.
I’m trying to get an existing experiment to run…

Hi @Andrew_Bangor

About the troubles with playing movies:

Just to make sure you have all the codecs installed, please, run:
sudo apt install ubuntu-restricted-extras

Also, there is a known bug related to playing videos on Ubuntu 22.04 using the preinstalled default app.
Luckily, the workaround is easy. Just remove gstreamer1.0-vaapi
sudo apt remove gstreamer1.0-vaapi

Please, let me know if that helps.

Cheers!

After folllowing all the steps above a Psychopy image does very briefly flash but then it exits with
13:24:15: Debug: “Shift+Tab” is not supported as a keyboard accelerator with GTK
Any suggestions?

Hi @simonrushton

  • Have you installed it on a clean install of Ubuntu 22.04.1?

  • Is the system up to date (all updates installed)? If not, try updating:
    sudo apt update
    sudo apt upgrade

  • I’ve been running Psychopy on Ubuntu using Xorg as window manager. Are you using Wayland (default) or Xorg? Please, try logging in using the “Ubuntu on Xorg” option.

  • What happens when you run:
    source Environments/psychopy-py38/bin/activate
    python
    import wx
    wx.version()

And, just to be sure: when you run Psychopy by typing
source Environments/psychopy-py38/bin/activate
psychopy --builder &
you must leave the terminal open. Closing the terminal also closes Psychopy Builder.

After a delay, I am back trying to get this to work. I had already installed ubuntu-restricted-extras as I needed them to get the movie to play outside of PsychoPy. I also had already tried removing gstrreamer1.0-vaapi.

I decided to try again with a clean install of 22.04LTS and your updated instructions. wxpython compile failed with a compiler error.

I will look into this and perhaps submit a bug against gcc.

[375/937] Compiling sip/cpp/sip_corewxNotifyEvent.cpp
In file included from …/…/…/…/ext/wxWidgets/include/wx/srchctrl.h:100,
from …/…/…/…/sip/cpp/sipAPI_core.h:22388,
from …/…/…/…/sip/cpp/sip_corewxOutputStream.cpp:10:
…/…/…/…/ext/wxWidgets/include/wx/gtk/srchctrl.h:27:5: internal compiler error: Segmentation fault
27 | }
| ^
0x7f9df97ab51f ???
./signal/…/sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
0x7f9df9792d8f __libc_start_call_main
…/sysdeps/nptl/libc_start_call_main.h:58
0x7f9df9792e3f __libc_start_main_impl
…/csu/libc-start.c:392
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <file:///usr/share/doc/gcc-11/README.Bugs> for instructions.

These instructions were great, and I got Psychopy to launch on our new 22.04 Ubuntu machines.

However, no experiments will run on our machines that have AMD Radeon GPUs. The demos will run fine on our NVIDIA GPU machines. I may make a separate thread for this one if there’s no traction here.

Anyone using AMD Radeon GPU with Ubuntu? Here’s what I get when I try to run a demo. Updating to latest Radeon driver didn’t help.

Running: /home/admin/miniconda3/envs/psychopy/lib/python3.8/site-packages/psychopy/demos/coder/stimuli/dots.py ##

pygame 2.1.2 (SDL 2.0.16, Python 3.8.16)

libGL error: MESA-LOADER: failed to open radeonsi: /usr/lib/dri/radeonsi_dri.so: cannot open shared object file: No such file or directory (search paths /usr/lib/x86_64-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri, suffix _dri)

Hello from the pygame community. https://www.pygame.org/contribute.html

libGL error: failed to load driver: radeonsi

libGL error: MESA-LOADER: failed to open radeonsi: /usr/lib/dri/radeonsi_dri.so: cannot open shared object file: No such file or directory (search paths /usr/lib/x86_64-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri, suffix _dri)

libGL error: failed to load driver: radeonsi

libGL error: MESA-LOADER: failed to open swrast: /usr/lib/dri/swrast_dri.so: cannot open shared object file: No such file or directory (search paths /usr/lib/x86_64-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri, suffix _dri)

libGL error: failed to load driver: swrast

thanks!
Mark

I’m running it on Ubuntu 22.04.1 with an AMD Radeon RX 6500 XT GPU. I tried both AMD driver and MESA driver. Everything works fine on my machine, though the performance (e.g., frame rate) is slightly worse than the same machine on Win 11.

Thanks! I’ll keep digging. Are you using Virtualenv or anaconda/miniconda? I will try virtualenv next to see if that makes a difference.

Update: Okay the issue seems conda related. When I switch to using Virtualenv, everything works just fine !

Update2: It also works in miniconda if I first add conda-forge channel and update conda, as described here.

1 Like

Hi @bastosfh, everyone,

Thanks for this really comprehensive guide. I wonder if you or anyone else would care to comment on a couple of things:
(1) How is this different from choosing a standalone install?
(2) How would you alter the instructions to work in a multi-user environment (i.e. a shared Linux workstation)?

E.g. I was thinking of moving my Environments folder to somewhere like /usr/local/psychopy/2022.2.4, then creating a symbolic link (ln -s /usr/local/psychopy/2022.2.4/Environments /home//) for each that wanted to use it? Providing the permissions were set correctly I assume this would work?

Each user would then start up PsychoPy as normal with:
source Environments/psychopy-py38/bin/activate
psychopy --builder &

Apart from the obvious limitations of other virtual environments being created in a common location on this shared Linux machine are there any other gotchas I should be worried about?

Lastly, how relevant are the instructions to run against python 3.8? Is PsychoPy playing nicely with python 3.10, so making the pip install psychopy method more straightforward…?

Sorry about all the questions…
Cheers, Jon

Hello there,

I have something look like easyer whith pipx :

sudo apt install python3-venv python3-pip pipx libsdl2-2.0-0

python3.10 -m venv .local/pipx/venvs/psychopy/

wget https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-22.04/wxPython-4.2.0-cp310-cp310-linux_x86_64.whl

pipx runpip psychopy install wxPython-4.2.0-cp310-cp310-linux_x86_64.whl 

pipx runpip psychopy install psychopy

ln -s /home/$USER/.local/pipx/venvs/psychopy/bin/psychopy /home/$USER/.local/bin/psychopy

pipx ensurepath

source .bashrc

Working on a fresh install of Ubuntu 22.04.2 but for now it’s the last version of psychopy 2023.1.1. I will try for 2022.2.4.

1 Like

Worked like a charm! Thank you so much!!!

Hi,

Nearly the same with psychopy==2022.2.4 :

sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.8-venv python3.8-pip pipx libsdl2-2.0-0 liblo-dev libportmidi-dev libsndfile1-dev portaudio19-dev 
python3.8 -m venv .local/pipx/venvs/psychopy2022/
wget https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-22.04/wxPython-4.2.0-cp38-cp38-linux_x86_64.whl
pipx runpip psychopy2022 install  wxPython-4.2.0-cp38-cp38-linux_x86_64.whl
pipx runpip psychopy2022 install psychopy==2022.2.4
ln -s /home/$USER/.local/pipx/venvs/psychopy2022/bin/psychopy /home/$USER/.local/bin/psychopy2022
pipx ensurepath
source .bashrc

I got psychopy 2023.1.0 to compile with python 3.8 on Ubuntu 22.04 using your technique. The below script should take care of everything, but you may need a reboot after disabling Wayland.

#Disable Wayland
sudo sed -i '/WaylandEnable=false/s/^#//g' /etc/gdm3/custom.conf

#Get Python 3.8
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install -y python3.8 python3.8-venv binfmt-support

#Get PIP 3.8
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3.8 get-pip.py

sudo apt install -y pipx python3-venv python3-sphinxbase python3-pocketsphinx python3-gst-1.0 python3-wxgtk-webview4.0 python3.8-distutils python3.8-dev gcc-python3-plugin swig pulseaudio* alsa* libwxgtk3* libwxgtk-webview3* libwebkit2gtk* webkit2gtk* libsdl2-2.0-0

#Make the VENV and build wxpython and pyschopy in it
python3.8 -m venv .local/pipx/venvs/psychopy38/
pipx runpip psychopy38 install numpy scipy matplotlib ipython pandas sympy nose suspect pysftp pyopenssl pyprowl python-periphery pydicom testresources PyQt5 pyparallel python-bidi sounddevice moviepy glfw opencv-python esprima astunparse arabic_reshaper pyftdi pyxid pyxid2 pyosf javascripthon pyftdi arabic-reshaper astunparse esprima freetype-py future gevent gitpython glfw imageio imageio-ffmpeg javascripthon jedi json-tricks matplotlib moviepy msgpack msgpack-numpy opencv-python openpyxl packaging pandas psutil pygame pyglet pyopengl pyqt5 python-bidi python-gitlab python-vlc pyyaml pyzmq questplus sounddevice soundfile tables ujson websocket-client xlrd psychtoolbox six wheel setuptools attrdict python-config

pipx runpip psychopy38 install wxPython
pipx runpip psychopy38 install --force-reinstall psychopy
ln -s /home/$USER/.local/pipx/venvs/psychopy38/bin/psychopy /home/$USER/.local/bin/psychopy38
pipx ensurepath
source .bashrc

then execute the following command from the terminal to open the builder, and Bob’s your uncle.

psychopy38 --builder &
1 Like

Thank you for the nice tutorual!

I followed it to the letter and keep getting stuck at building wheel for wxPython (setup.py). This processes maxes out my cpu and just goes on forever. Any advice?

UPDATE:

fixed the problem by manually installing wxPython. So, i just added two steps before installing psychopy

wget https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-22.04/wxPython-4.2.0-cp38-cp38-linux_x86_64.whl
pip install wxPython-4.2.0-cp310-cp310-linux_x86_64.whl
pip install psychopy==2022.2.4

Hi, Rodrigo!

Which Linux distribution and version are you using (e.g. Ubuntu 22.04)?

Which PsychoPy version have you installed (it is shown on Builder’s top window)?

The warning may be caused by a dependency not installed…
Since you installed PsychoPy using conda, I believe you haven’t followed this tutorial, right?

The “extra configurations” you are looking for (the ones I linked on that ‘here’) are these:

Raise the priority of the experiment process

sudo groupadd --force psychtoolbox
sudo usermod -a -G psychtoolbox $USER

Create a 99-psychopylimits.conf file using gedit:

sudo gedit /etc/security/limits.d/99-psychopylimits.conf

Paste in the following text to that file and save it:

@psychtoolbox - nice -20
@psychtoolbox - rtprio 50
@psychtoolbox - memlock unlimited

PS: Thanks for the ‘happy birthday’ :slight_smile:

Best regards,
Flavio