How to install PsychoPy on Ubuntu 21.10

Hi everyone,

I’ve found some time to play with the installation of PsychoPy in Ubuntu 21.10 and, as it went well, I thought someone else could need this. Hopefully, this set of instructions will also work with Ubuntu 22.04, the upcoming LTS version.

It worked in a clean install of Ubuntu 21.10 and PsychoPy 2021.2.3.

First, install outdated psychopy from Ubuntu’s repository

sudo apt install psychopy

Install pip3

sudo apt install pip3

Now, install the packages needed to compile wxPython

sudo apt install python3-pip make gcc libgtk-3-dev libgstreamer-gl1.0-0 freeglut3 freeglut3-dev python3-gst-1.0 libglib2.0-dev ubuntu-restricted-extras libgstreamer-plugins-base1.0-dev

To compile/build your wxPython, “ask” pip3 to force reinstall. Otherwise, it is going to use the xwPython version from Ubuntu’s repository (which won’t work - at least, not for me). This is going to take a while, so press enter and go have some coffee :wink:

pip3 install -v --user -- force-reinstall wxPython

Install Psychtoolbox bindings

sudo apt install libusb-1.0-0-dev portaudio19-dev libasound2-dev

Update psychopy using pip3

pip3 install -U psychopy

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

Finally, to avoid Builder to crash when you insert a $ into a textbox, edit the paramCtrls.py file ([python-package-directory]/psychopy/app/builder/dialogs/paramCtrls.py).
Open the file using gedit and find where updateCodeFont is defined. You just have to comment one line and add another, as indicated below:

    def updateCodeFont(self, valType):
        """Style input box according to code wanted"""
        if not hasattr(self, "SetFont"):
            # Skip if font not applicable to object type
            return
        if self.GetName() == "name":
            # Name is never code
            valType = "str"
        if valType == "code" or hasattr(self, "dollarLbl"):
            # Set font
            # self.SetFont(self.GetTopLevelParent().app._codeFont.Bold()) # Comment this line
            self.SetFont(self.GetTopLevelParent().app._mainFont) # Add this line
        else:
            self.SetFont(self.GetTopLevelParent().app._mainFont)

Now, you are good to go :wink:
Have fun using Builder in Ubuntu 21.10!

2 Likes

Hi everyone,

I’ve successfully installed PsychoPy 2022.1.1 on Ubuntu 21.10.
Since there was substantial differences in the process, compared to PsychoPy 2021.2.3, here is how I did it.

First, install outdated psychopy from Ubuntu’s repository

sudo apt install psychopy

Now, install pip3, some Psychtoolbox bidings and packages needed to compile wxPython and some Psychopy dependencies (as pocketsphinx, for instance):

sudo apt install python3-pip make gcc libgtk-3-dev libgstreamer-gl1.0-0 python3-gst-1.0 libglib2.0-dev ubuntu-restricted-extras python-dev bison autoconf libtool-bin swig libpulse-dev libusb-1.0-0-dev portaudio19-dev libasound2-dev freeglut3 freeglut3-dev libgl1-mesa-dev libglu1-mesa-dev libgstreamer-plugins-base1.0-dev libgtk-3-dev libjpeg-dev libnotify-dev libsdl2-dev libsm-dev libtiff-dev libwebkit2gtk-4.0-dev libxtst-dev

Two dependencies are not installed automatically and are needed to compile wxPython and run PsychoPy when the installation is finished. To get rid of them run:

pip3 install testresources pyosf

Now, to download and compile/build your wxPython, ask pip3 to force reinstall, otherwise, it is going to use the xwPython version from Ubuntu’s repository (which won’t work - at least, not for me). This is going to take a while… So, paste the line below into the Terminal, press enter and go have some coffee :wink:

pip3 install -v --user --no-cache-dir --force-reinstall wxPython

Update psychopy using pip3

pip3 install -U psychopy

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

If you get an error while trying to save your experiment using Builder, an outdated defusedxml might be the culprit. Just update it with:

pip3 install -U defusedxml

In this new version, Builder does not crash anymore when you insert a $ into a textbox (Hurray!).

Now, you are good to go :wink:
Have fun using PsychoPy 2022.1.1 in Ubuntu 21.10!

2 Likes

Thanks for the info!

I’m curious, for the wxPython installation it seems like your force-reinstall call isn’t using the wheel that you took the effort to download. Installing the wheel should be extremely quick, with no compiling. I think for that one you could be using something like this (untested) to download and install from that location:

pip3 install -v --user --force-reinstall https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-20.04/wxPython-4.1.1-cp38-cp38-linux_x86_64.whl

For setting the priority: we’ve looked into what we can do to make this easier. In 2022.1 we now check if a file has been created in

Hi @jon!

The end of your message is missing and I would very much like to know about developments into setting the priority level.

About the wxPython, installing the downloaded version was causing some error messages that stopped when I compiled it (possibly because there was no wxPython pre-compiled to Ubuntu 21.10).

I’m working on a “how-to” to install PsychoPy on Ubuntu 22.04. Would it be better to post it here (as a reply to this thread) or to start a new one?

Best regards!

1 Like

Oh, not sure what happened there. I was saying that the app itself should now checks for a /etc/security/limits.d/99-psychopylimits.conf file and if it doesn’t find one it brings up a dialog alerting the user the lines they should add to create one. See the code in this PR NF: Prompt for linux specific configuration by mdcutone · Pull Request #4541 · psychopy/psychopy · GitHub

best wishes
Jon

Ideally update the docs themselves (which live in the github repo):
psychopy/download.rst at release · psychopy/psychopy · GitHub
but I guess putting them in a new thread on discourse by version number is good too