Python for Experimental Psychologists

Python for Experimental Psychologists is a book that is targeted at people in Experimental Psychology or Cognitive Neuroscience, who have no previous experience with Python or programming. It is suitable for students and staff, and aims to provide a basic working proficiency in Python. After working your way through the book, you will have the knowledge and skills required to script experiments and analyses. You can order the book from Routledge’s website.

Dalmaijer (2016) Python for Experimental Psychologists

Supporting materials

Occasionally, the book refers to files on a support website. You can find those below, organised per chapter. You can also download them in one big ZIP archive (those are files with a .zip extension).

If you’re unfamiliar with ZIP archives, here’s come background. Archives are essentially compressed folders that contain files. After downloading them from this website, you’ll need to extract them before you can use them. Fortunately, that’s not a difficult thing to do! On Mac OS X, double-clicking the archive will automatically extract the files. On most Linux distributions, you can right-click on the archive, and then select ‘Extract here‘. On Windows, you could also right-click on the archive, and select ‘Extract All…‘.

Alternatively, you can extract the files from an archive using a tool like 7-Zip. After installation, you can open archives in 7-Zip. You can also right-click on the .zip file, then select ‘7-Zip‘, and ‘Extract here‘.

WinPython PyGaze

If you’re a Windows user, you could use a completely portable version of Python. It doesn’t require any installation; just download the package, and then unzip it.


Download all files in one ZIP archive. After downloading the archive, make sure you extract it properly (for example with a tool like 7-Zip, which is explained above).

Chapter 3

Chapter 4

Chapter 5

Chapter 6

Chapter 7

Chapter 8

Make Some Noise 1 (visual)

Make Some Noise 2 (sound)

Make Some Noise 3 (musical instrument)


  • Dalmaijer, E.S. (2016). Python for Experimental Psychologists. Abingdon, United Kingdom: Routledge (part of Taylor and Francis Group). More information, and ordering.


  1. Hi Edwin,
    I’ve been reading your book to learn python (it is clear and interesting!) and bumping into problems.

    I followed instructions in the book to build the experiment, and it worked fine before ‘Logging values’. After adding codes in that section, Spyder crashed right after I entered the participant name and hit ‘Enter’. I tried to open the script with interpreter (Using WinPython interpreter) and it crashed too. Though I corrected every parts in my script, it did not work.
    The Whole_experiment_Pygaze script (answer in chapter 5) crashed in the same way. I’m really confused…
    Any ideas?

    I’m using Windows 10 and WinPython-PyGaze-0.5.1 downloaded here to program.

    Many thanks,

    • Hi Elliot,

      Thanks for buying the book! Sorry you’re running into troubles, but I’m sure we can solve them :)

      The code in the book has been tested very thoroughly, but just to make sure, I’ve downloaded the package and the scripts from here. When running them on Windows 7, everything runs smoothly. So I’m sure that the code is fine.

      Let’s start fixing your issues by going through the basic steps to run the whole experiment from Chapter 5 (PyGaze version):

      1. It’s never a good idea to run whole experiment scripts through Spyder’s console. As the book explains, it’s better to use the Command Prompt or a batch file.
      2. The WinPython Interpreter is a Python interpreter. You’re better of using the WinPython Command Prompt instead.
      3. Launch ‘WinPython Command Prompt.exe’
      4. Type the following command:
        python "PATH\"
        Where PATH should be replaced by the actual path to your file, for example: C:\Users\Elliot\Documents\PEP_Chapter_05_code2_Whole_experiment_PyGaze
      5. After hitting Enter, your experiment should run (starting with a prompt for the participant name, and then opening the experiment window).

      As I said, that all works on my Windows 7 machine here, just using the downloaded WinPython package and experiment scripts. If it doesn’t work for you, please include screen captures of error messages etc., as we will need those to diagnose the issue.

      Good luck!

      • Hi Edwin,

        Sorry for late response, the experiment runs as expected now!
        Thank you for the detailed explanation!

        Many thanks,

  2. Hi Edwin,

    Firstly, thank you for creating an excellent resource. I bought your book as learning Python is my summer project and this book has already taught me so much

    I have however hit a stumbling block. I am currently up to the stage of monitoring keyboard input (p57) but am receiving the following the error when running the current script

    I can send the full error message if this would help but at this point I am beyond confused. The code for the scripts match the examples so I am completely stuck. Any help would be greatly apppreciated



    • Hi Stephen,

      Thanks for the compliments! I’m sorry you ran into an error. Would you mind posting the script, or at the very least the bit where the error occurs, and also the error message? (It seems like it didn’t come through in your post.)

      You can always email them to too. It’d be great if you could email the full script, actually, so I can check for errors. (Likely candidates are quotation marks and hyphens; sometimes they look the same to human eyes, but not to a Python Interpreter 😉 )


      • Thanks for the speedy response Edwin. I managed to resolve the issue. You were absolutely correct. Quotation marks were the issue. I will make sure to use your email should I run into any more issues. Again, thanks for such an excellent resource



  3. I’ve just started learning Python and I’m a full time psychology student. Is this book suitable for beginners like me?

    Thank you, Edwin!

    • Yes, it most definitely is for you! The book starts with the very basics: Fundamental concepts like “object-oriented programming” are explained in a friendly way, and Python is introduced for complete beginners. (You can always skip the basics chapter if you already know a bit of Python.)

  4. Hi Edwin, One of the professors at a python meetup in seattle recommended your program and I’ve been looking for it, tonight I found it.

    I’m very curious about the implication or purpose for your book. Is the code and content of the book for diagnostics, for analytics or research into experimental treatments?

    What would someone use the book for?

    What are the applications for your book in Ai or ML in the field of psychology?

    • Hi Andrew,

      Thanks for you questions! Great to hear that people are recommending this :)

      The book is written for experimental psychologists, and has three main functions: 1) To teach the basics of Python programming, 2) To teach how to create psychological experiments in Python using the PyGaze and/or PsychoPy libraries, and 3) To do some data wrangling, statistics, and visualisation (using NumPy, SciPy, and Matplotlib).

      The typical use cases that I have seen are for first-year PhD students looking to learn Python, but I’ve also seen it adopted by more senior staff, and also by MSc and BSc students.

      I should note that the current edition is a bit old at this point, and still focusses on Python 2.7. The next edition will focus on Python 3, and will include more chapters on stats. (Not full-on AI and machine learning, though: other people have filled whole books with that, e.g. Python Machine Learning by Sebastian Raschka and Vahid Mirjalili.)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">