2. Software Installation

We explain below how to install:

  • a code editor: Visual Studio Code

  • a version control system: Git

  • the statistical programming language R

  • the integrated development environment RStudio

  • The programming language Python (version 3.7 !)

  • The experiment generator Expyriment (python module)

After the installation, you will need to check that everything works (see Check your installation

Warning

  • You will need to download several GB of software from the Internet. Therefore, make sure to have a decent connection.

  • Make sure that you have at least 5GB of free space on your hard drive to unpack the various software.

  • You will need to have administrator rights to install some of the software. If you are using a computer from an institution, check with the IT support team.

2.1. Instructions for native Windows (without WSL)

Please follow these instructions carefully! If you do not, many things could go wrong and you might need to run the installers again.

2.1.1. R and Rstudio

R is a programming language specialized for statistical data analyses; Download and install it from https://cran.rstudio.com/bin/windows/base/ (accepting all the default options proposed by the installer)

Rstudio is an Integrated Developpement Environment for R which greatly simplifies the use of RMarkdown. You can download and install the free version of RStudio Desktop from https://posit.co/download/rstudio-desktop/ (accepting all the default options)

Lauch RStudio, go to the “Tools” menu, select “install packages” and in the dialog window that opens, in the ‘packages’ box, type:

tidyverse lme4 ez

This will take a while to download packages from the internet and install them. Do not close rstudio until the process is finished (no more scrolling messages in the console). Meanwhile, you can start the installation of the other software below.

2.1.2. Code editor

A code editor is a program that allows you to edit pure text files such as Python programs, Markdown or LaTeX documents, etc.

If you do not already have a code editor that you like, download and install Visual Studio Code (accepting the default options proposed by the installer)

2.1.3. Python3 using the Anaconda distribution

You will need to install Python version 3.7 (because the expyriment module, to be installed later, requires this specific version)

There exists various Python distributions. Under Windows, we recommend the Anaconda3 distribution as it already contains many of the packages needed for cognitive science (but it is very large. If you you lack disk space, you can install miniconda, but later you will need to install many python packages manually)

  1. Go to <https://www.anaconda.com/products/individual>, click on Download and select the 64-bit installer for Windows.

  2. Execute the Anaconda3 installer. Pay special attention to the options:

    • To the question ‘Install for’, select Just Me (recommended)

    • Accept the default Destination folder and click on Next

    • VERY IMPORTANT: Check the boxes in front Add Anaconda3 to my PATH (ignore the warning that this is not recommended) and Register Anaconda as my default Python (all the other default options are fine). Click on Install.

    • upon completion, click on Next, then Finish

2.1.4. The Git version control system

Git is a version control tool for software development, an indispensable tool to do reproducible science.

IMPORTANT: you must wait for the installation of Anaconda to finish before trying to install Git.

Download the installer of Git for Windows and launch it.

  1. When the GNU Licence is displayed, press Next;

  2. Accept the default installation folder and press Next;

  3. Accept all the Components selected by default and press Next

  4. Accept the creation of a start menu folder named ‘Git’: press Next;

  5. VERY IMPORTANT: When proposed a default editor, select ‘Use the nano editor’ (unless you want to learn Vim)

  6. VERY IMPORTANT: When proposed to adjust the PATH environment variable, tick the box “Use Git and optional unix tools from the command line prompt”.

You can accept all the other defaults.

Now, to finish the installation of git, launch Git bash (use the “Search box”), and on type:

conda init bash

then press ‘Return’

If the computer replies with an error message of the type conda: command not found, you did not properly install Anaconda (you did not check the box that made sure it is added to the PATH). If you know how to do correct the PATH, correct it now, otherwise, reinstall anaconda.

Now, type:

echo "alias python='winpty python.exe'" >> ~/.bash_profile

and press ‘Return’

Close the Git Bash Terminal, and reopen a new Git Bash.

Type:

which python

And then:

python

It should print a message ‘Python 3.x.xx…’ and a give a prompt ‘>>>’. You are talking to the python interpreter. Type:

2**100

This should display the 100 power of 2. To exit python, type:

quit()

If python does not start, there is something wrong. Most probably, you forgot to check the boxe Add Anaconda to my PATH during the installation of Anaconda. do it again. If it still does not work, ask for help.

Finally, you must configure Git: Within a Git Bash terminal, type the following commands (replacing your_first_and_last_name_here and your_email_here by relevant personal information)

git config --global user.name "your_first_and_last_names_here"
git config --global user.email your_email_here
git config --global core.editor nano

You can close Git Bash by typing the command exit or, faster, by pressing Ctrl-D, or by just closing its window.

2.1.5. The Pygame and Expyriment python modules

We will rely on the Pygame module to create stimuli and the Expyriment Python Library to program behavorial experiments.

Start Git bash and, in the Terminal that opens, type:

conda create -n expyriment python=3.7

And press ‘Return’ to accept the installation.

Then, type:

conda activate expyriment
conda install ipython
pip install expyriment[all]

To check the installation, type:

ipython

and then:

import expyriment

If a message Experiment 0.10.0 … is displayed and no error message, the installation worked. Press Ctrl-D to quit ipython, and Ctrl-D again to qui Git Bash.

2.1.6. Checking everything

Now you should check if everything works, following the instructions in chapter Check your installation.

2.2. Instructions for Windows using the Windows Subsystem for Linux (WSL)

As an alternative to installing Python et coll. as native Windows applications, you can install Ubuntu Linux under Windows, relying on Microsoft’s Windows Subsystem for Linux (aka WSL) and then install Python and coll. within Ubuntu.

The interest of having WSL is that it gives you the opportunity to learn to use Linux, which may come handy if one day you need to access remote computational facilities such as the Jean Zay supercomputer.

If you already have WSL Ubuntu installed on your Windows PC, you can just open an Ubuntu terminal and jump directly to the linux section.

If not, and want to try it, keep reading.

2.2.1. Installing the Microsoft’s Windows Subsystem for Linux

If you want to install Linux under Windows using the WSL, follow the instructions at https://docs.microsoft.com/en-us/windows/wsl/install but be aware that the download is large (several GB) and the installation can be lengthy, depeding on the power of your PC (30min-1h)

Here is an overview of the process:

  • If you have Windows 11:

    1. Install the vGPU driver for your graphics card (Intel, AMD or Nvidia) [2] if it not already installed.

    2. Launch “Windows PowerShell” as administrator, and execute the command:

      wsl --install -d ubuntu
      
  • If you have Windows 10, follow these instructions. (You may have to enable Hyper-V)

This downloads the full Ubuntu Linux distribution which may take a while. Some versions of Windows may even ask you to reboot during the installation process. At some point during the install, a new Terminal window entitled “Ubuntu” will open and will require a new user name and password. You can type anything but it is crucial that you note down the password as it will be needed to install software under Ubuntu.

Note

If anything goes wrong during the installation check the Troubleshoting WSL section.

Now that the WSL installation is finished, jump to the linux section in order to install the required software.

2.3. Instructions for MacOS X

2.3.1. Code editor

A code editor is a program that allows you to edit pure text files such as Python programs, Markdown or LaTeX documents, etc.

Unless you already use a code editor that you are familiar and happy with, we recommend that you download and install Visual Studio Code. Follow the instructions specific to MacOS.

2.3.2. The Git version control system

Download and install Xcode, either from the App store, or by using the command line xcode-select --install. This will provide git.

To finish the installation of git, open a Terminal window [1] and type the following command lines, making sure to replace your_first_and_last_name_here and your_email_here by the relevant personal information:

git config --global user.name "your_first_and_last_names_here"
git config --global user.email your_email_here
git config --global core.editor nano

2.3.3. The R statistical software

Download and install the latest version of R from https://cran.rstudio.com/bin/macosx/

2.3.4. Rstudio Desktop

Download and install the latest version of RStudio Desktop from https://posit.co/download/rstudio-desktop/. Make sure to select the MacOS version!

2.3.5. Python

Download and install Anaconda3 Python from https://www.anaconda.com/products/individual

2.3.6. The Pygame and Expyriment python modules

  1. Install XQuartz. Download the .dmg file from the official website and open it to install.

  2. Open a Terminal and type /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" to install Homebrew (which is needed to install SDL).

    • If you see “Password: “, this means the Terminal is prompting you to type your computer’s administrator account password. Type your password and press the return key to continue.

    • If you see an error message such as “Error: /usr/local/Cellar is not writable. You should change the ownership and permissions of /usr/local/Cellar back to your user account: sudo chown -R $(whoami) /usr/local/Cellar”, run in the Terminal the command that was suggested (here sudo chown -R $(whoami) /usr/local/Cellar), and then run the previous command to try installing Homebrew once again

  1. In the same Terminal, type brew install sdl2 sdl2_image sdl2_mixer sdl2_ttf pkg-config to install SDL (which is needed to install expyriment). This may take a while.

  2. In the same Terminal, type pip install "expyriment[all]" to install expyriment.

  3. In the same Terminal, type pip install -U pygame to upgrade pygame (version >= 2.0 is required on recent versions of macOS, but this must be done after installing expyriment otherwise the install of expyriment will fail).

Now you should check if everything works, following the instructions in chapter Check your installation.

2.4. Instructions for Ubuntu Linux

These instructions were tested with Ubuntu 20.04

Open a Terminal [1].

Then, for each software section below, copy and paste in the terminal the lines that are in the boxes and press Enter to execute them.

2.4.1. Git

Git is a free distributed version control system.

sudo apt install git -y

Now, type the following command lines, making sure to replace your_first_and_last_name_here and your_email_here by the relevant personal information:

git config --global user.name "your_first_and_last_names_here"
git config --global user.email your_email_here
git config --global core.editor nano

2.4.2. Visual Studio Code editor

Install Visual Studio Code:

snap install code

2.4.3. R language for statistics

R is a free software environment for statistical computing and graphics.

sudo apt update -qq

sudo apt install –no-install-recommends software-properties-common dirmngr wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | sudo tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc sudo add-apt-repository “deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/”

sudo apt install –no-install-recommends r-base sudo add-apt-repository ppa:c2d4u.team/c2d4u4.0+ sudo apt install –no-install-recommends r-cran-tidyverse

(in case of trouble, check the latest instructions at https://cran.rstudio.com/bin/linux/ubuntu/)

2.4.4. Rstudio Desktop

Rstudio is an Integrated Developpement Environment for R which greatly simplifies the use of RMarkdown. You can download and install the latest version of RStudio Desktop from https://posit.co/download/rstudio-desktop/ Make sure to select the ubuntu version!

wget https://download1.rstudio.org/electron/jammy/amd64/rstudio-2023.06.2-561-amd64.deb
sudo apt install ./rstudio-2023.06.2-561-amd64.deb -y

2.4.5. Python3

Python is the main programming language used in these courses. The following commands install various modules that will be needed.

sudo apt  install -y python3 ipython3 python3-dev python-is-python3 python3-future \
          python3-opengl python3-pip python3-ipython python3-pygame python3-numpy \
          python3-matplotlib python3-skimage python3-pandas python3-scipy \
          python3-imageio python3-ipython

2.4.6. Expyriment

We now need to install the Expyriment module.

Try:

sudo apt-get install -y python3-dev libasound2-dev
sudo pip install simpleaudio

sudo pip install expyriment[all]

Check the installation by typing:

python

and then, after >>>:

import expyriment

If you see No module named expyriment, there was a problem (most probably due a version of pygame). Forcing the using of python version 3.7 should solve it.

First install pyenv, then:

pyenv install 3.7.6
pyenv virtualenv 3.7.6 expyriment
pyenv activate expyriment
pip install expyriment[all]

Note: Later, when you will need to run python scripts importing expyriment, you will need first to activate the virtual environment with:

pyenv activate expyriment

2.4.7. Psychtoolbox

(This is optional: we do not make use of the Psychtoolbox in this course)

Psychtoolbox-3 is a set Octave functions which is very popular in vision and neuroscience research. This installation is optional as the Psychtoolbox is not used in this book.

First, add the [Neurodebian](https://neuro.debian.net/) repository.

wget -O- http://neuro.debian.net/lists/focal.de-m.full | sudo tee /etc/apt/sources.list.d/neurodebian.sources.list
sudo apt-key adv --recv-keys --keyserver hkps://keyserver.ubuntu.com 0xA5D32F012649A5A9

Then activate the sources and install the required packages:

sudo sed -Ei 's/^# deb-src /deb-src /' /etc/apt/sources.list
sudo apt update

sudo apt build-dep octave-psychtoolbox-3 -y
sudo apt install subversion libdc1394-22-dev libfreenect* libgstreamer1.0-dev libgstreamer-plugins-* -y

Download the psychtoolbox installation script:

wget https://raw.github.com/Psychtoolbox-3/Psychtoolbox-3/master/Psychtoolbox/DownloadPsychtoolbox.m.zip
unzip DownloadPsychtoolbox.m.zip

mkdir ~/PTB3

Finally, start octave and, on Octave’s command line, type:

DownloadPsychtoolbox('/home/neurostim/PTB3')
PsychLinuxConfiguration()

# test
DrawingSpeedTest()

Now you should check if everything works, following the instructions in chapter Check your installation.