Month: September 2017

Instructions for Installing PsychoPy

PsychoPy is an experiment development program and Python library. It is free and open source software with a community contributing to its development and maintenance. The experiments are written in Python, which is a popular general-purpose programming language with a great deal of information to support users with any issues. These properties make it a strong alternative to proprietary programs.

To install PsychoPy, you should first decide whether you want to install the standalone builder or the Python library.

The standalone builder is available for Windows and MacOSX. It allows you to build the experiments without installing any additional dependencies. It is based around a graphical user interface (GUI) that allows you to drag-and-drop elements of your experiment without needing to code everything yourself, though it also has a code editor for fine-tuning. It is the recommended option if you do not already have a Python development environment set up on your computer and do not have immediate plans to set one up.

The Python library is available for all operating systems. It is a lighter-weight alternative which is recommended if you already have Python installed on your computer, or want to get one set up now. The library does include a GUI builder (though it takes a couple extra steps to make the GUI readily accessible), but also allows you to build or edit your experiments in the text editor of your choice.

Standalone builder: Windows & MacOSX

Go to the PsychoPy installation page and download and run the installer for your operating system.

Python library

There are a few options for installing the Python library. If you are using Linux, your distribution might have a package ready for you to install. Otherwise, jump to Other systems.

Debian-based systems (e.g., Debian, Ubuntu, Linux Mint)

Add the NeuroDebian repository by following the instructions for your system on the NeuroDebian website. Remember to run sudo apt-get update after you have added the repository.

Then, install PsychoPy by running:

sudo apt install psychopy

Arch-based systems (e.g., Arch Linux, Manjaro)

Install PsychoPy from the Arch User Repository by running

yaourt psychopy

This will install PsychoPy to /usr/bin/psychopyApp.py. It should include a desktop file, meaning that you should be able to find it in your dmenu. But, you will not be able to run the builder from your terminal by typing psychopy. If you wish to do so, you should add an alias to your rcfile (e.g., ~/.bashrc or ~/.zshrc):

alias psychopy="/usr/bin/psychopyApp.py -b"

(the -b flag means "run the builder").

Other systems

You will need Python 2.7 on your computer in order to install the Python library. The easiest way to install and manage Python and all of the dependencies for PsychoPy is to use Anaconda Python. Even if you already have Python on your computer, you will likely want to install Anaconda Python, because not all of PsychoPy’s dependencies are available on PyPI.

Installing Anaconda Python

To install Anaconda Python, go to the Anaconda downloads page and download and run the installer for your system. You can choose either Python 2.7 (recommended if you do not plan on using Python outside of PsychoPy) or Python 3.x (recommended if you do plan on using Python for other purposes); you will be able to run a Python 2.7 environment either way.

Installing the PsychoPy library

Once you have Anaconda Python installed on your computer, you will need to create an environment for PsychoPy.

Open a command prompt (Windows) or a terminal (Mac/Linux) and enter the following:

conda create -n psychopy --channel https://conda.anaconda.org/CogSci psychopy pyglet wxpython pygame python=2.7

which means:

  • conda create: use (Ana)conda to create a Python environment
  • -n psychopy: named "psychopy"
  • --channel https://conda.anaconda.org/CogSci: in addition to the normal package sources, look in the "CogSci" channel for the packages I need
  • psychopy pyglet wxpython pygame: install these packages and any other packages that they depend on
  • python=2.7: use Python 2.7 in this environment

Starting PsychoPy

To start the PsychoPy builder, enter the following in your terminal/command prompt:

Mac/Linux
source activate psychopy
~/.conda/envs/psychopy-instructions/lib/python2.7/site-packages/psychopy/app/psychopyApp.py -b

Then, when you are done, enter:

source deactivate

to leave the PsychoPy environment.

Windows
activate psychopy
C:\Users\[YOURNAME]\Anaconda3\envs\psychopy\Lib\site-packages\psychopy\app\psychopyApp.py -b

and when you are done, leave the environment by entering:

deactivate

Running a PsychoPy script

If you have a PsychoPy experiment script that you would like to run, you do not need to open the builder to do so. You can run it from the command line.

First, open a command prompt or terminal.

"Change directories" (cd) into the folder containing the script file by entering cd <folder-path>. For example, cd C:\Users\YOURNAME\Documents\Experiments or cd /home/Users/YOURNAME/Documents/Experiments. (Hint: you can type the first few letters of each part and then hit the tab key to complete it).

Then start up your PsychoPy environment by entering activate psychopy (Windows) or source activate psychopy (Mac and Linux).

Then you can run the script by entering python experiment.py (replace experiment.py) with the actual file name.

When you’re done working on it, enter deactivate (Windows) or source deactivate (Mac or Linux) to leave the PsychoPy environment.

Troubleshooting

  • When you try to run the builder, if you installed the Python library, you might get errors that some packages are not installed. You can install these by entering conda install packagename or pip install packagename.

  • If the builder (with any installation) consistently crashes when you start it, there may be a problem with the configuration files. You can try editing them in a text editor, or you can delete them completely—they will be regenerated the next time you start the program, hopefully not containing any issues that would cause PsychoPy to crash. (See PsychoPy’s troubleshooting page for more information.) On Mac and Linux, those files can be found:

~/.psychopy2/appData.cfg
~/.psychopy2/userPrefs.cfg

And on Windows:

${DOCS AND SETTINGS}\{USER}\Application Data\psychopy2\appData.cfg
${DOCS AND SETTINGS}\{USER}\Application Data\psychopy2\userPrefs.cfg