Difference between revisions of "Psychopy"

From TSG Doc
Jump to navigation Jump to search
 
(45 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{mbox
+
 
| type = notice
 
| text = There will be a Psychopy [http://tsgdoc.socsci.ru.nl/index.php?title=Workshop:_Python_for_social_scientists workshop] in april
 
| image = {{{image|}}}
 
}}
 
 
{{Infobox software
 
{{Infobox software
 
| name                  = Psychopy
 
| name                  = Psychopy
Line 31: Line 27:
 
   {{Infobox tsg
 
   {{Infobox tsg
 
     | child              = yes
 
     | child              = yes
     | downloads          = {{bulleted list
+
     | downloads          =  
         | [[Media:TemplatePsychopy2013.zip|Template]]
+
         * [https://gitlab.socsci.ru.nl/utilities/psychopytemplate  Template / Working Example]
    }}
+
        * [https://gitlab.socsci.ru.nl/utilities/psychopytemplate/-/blob/main/runexperiment.py?ref_type=heads  MainCode for Template / Working Example]
 +
 
 
     | manuals            = {{bulleted list
 
     | manuals            = {{bulleted list
         | [https://www.socsci.ru.nl/~wilberth/psychopy/index.html Course]
+
         | [https://www.socsci.ru.nl/wilberth/psychopy/index.html Course]
 
     }}
 
     }}
 
   }}
 
   }}
 
}}
 
}}
 
'''Psychopy on the labcomputers'''
 
 
 
PsychoPy is an alternative to Presentation, e-Prime and Inquisit. It is a Python library and application that allows presentation of stimuli and collection of data for a wide range of neuroscience, psychology and psychophysics experiments. When used on DCC computers PsychoPy is guaranteed to be millisecond accurate.
 
PsychoPy is an alternative to Presentation, e-Prime and Inquisit. It is a Python library and application that allows presentation of stimuli and collection of data for a wide range of neuroscience, psychology and psychophysics experiments. When used on DCC computers PsychoPy is guaranteed to be millisecond accurate.
  
Since Python version 2.7 has reached end of life since January first 2020, this version is no longer installed on the PCs in the labs. Standard is now: Python 3.7 64-bits.
+
==Installation==
If you still have scripts written in Python2, the scripts should be upgraded to Python 3. Most changes are probably the print statements. Print statements should always have parentheses: print('some text')
+
We recommend to use a modern 64-bit version of Python. In our labs, we currently have Python 3.8.10 64 bits installed. Psychopy recommends Python 3.8.10.
Key differences between Python 2 and Python 3 are here: https://sebastianraschka.com/Articles/2014_python_2_3_key_diff.html
 
 
 
Psychopy 2020.2.10 has been installed in the root of the Python3.7 64-bit version. This is also the default version when 'psychopy' is typed from the command prompt. It is also the default that opens when a .py file is double-clicked. It also can be started by clicking the appropriate icon on the desktop.
 
There is also a Psychopy 2020.2.10 installed on Python3.6 32-bits. This version has its own icon on the desktop and should be used when you are using a TOBII Eyetracker.
 
 
When your script fails to load in Psychopy, because you need packages that are not installed on our labcomputers, please contact TSG.
 
 
 
On the labcomputer, there is support for Spyder, PyCharm and Psychopy.  
 
  
 +
Check our gitlab server https://gitlab.socsci.ru.nl/tsg/psychopy2024.1.0install
  
'''The information below is outdated.'''
+
=== For Pavlovia users ===
 +
If you want to upload experiments to Pavlovia, you will need to install [https://github.com/git-for-windows/git/releases/download/v2.17.1.windows.1/Git-2.17.1-64-bit.exe Git-2.17.1-64-bit.exe] using these instructions: [https://gitlab.socsci.ru.nl/h.voogd/git-2.17.1.2-64-bit.exe/-/raw/master/GitInstall.docx GitInstall.docx]. Then, in
 +
''System| Advanced system settings | Environment variables'', add the folder where ''git-daemon.exe'' is, to the PATH variable. Usually, that folder is named: 'C:\Program Files\Git\mingw64\libexec\git-core'.
  
== Installation ==
+
===Lab computer versioning===
{{see also|Psychopy installation}}
 
Click [http://www.psychopy.org/installation.html here] for more information on installing PsychoPy. For Radboud Social Sciences specific instructions, visit the [[Psychopy installation]] page.
 
  
  
== Learning PsychoPy ==
+
A default version of Psychopy has been installed in the root of the Python3.8.10 64-bit version. This is also the default version when 'psychopy' is typed from the command prompt. It is also the default that opens when a .py file is double-clicked. It also can be started by clicking the appropriate icon on the desktop. One in a while, the default version is upgraded to a newer version. The older version is then still available in a virtualenv.
* [https://www.socsci.ru.nl/wilberth/psychopy/index.html psychopy tutorial website]
 
* [[PsychoPy-Matplotlib|Combining Psychopy and Matplotlib]]
 
  
== Templates ==
+
Find the presentation Template here [[Media:TemplatePsychopy2013.zip]]
+
When your script fails to load in Psychopy, because you need packages that are not installed on our labcomputers, please contact TSG.
  
== Troubleshooting ==
+
On the labcomputer, there is support for Spyder, PyCharm and Psychopy.  
 
 
==== Version Change to 1.85 ====
 
 
 
If you use audio in psychopy, but you do not choose the back-end yourself (this is the default method), then sound will be played in a different, more reliable way.
 
This may lead to slightly larger but still small latency.We do not expect this to be problematic.
 
If you have any questions about this, come to TSG.
 
Do you use audio in psychopy and choose your own backend with the following line:
 
 
 
''prefs.general['audioLib'] = ['pyo']''
 
  
change this
+
=== For SR-Research Eyelink users ===
 +
Pylink is installed on our lab computers.
  
''prefs.general['audioLib'] = ['sounddevice']''
+
=== For SMI RED 500 and SMI HiSpeed Tower users ===
 +
Include this file into your project: [https://gitlab.socsci.ru.nl/h.voogd/iviewxudp iViewXudp]. This should work on both 64-bit and 32-bit Python 3 versions.
  
This may lead to slightly larger but still small latency. We do not expect this to be problematic.
+
=== For Tobii Studio ===
 +
Check this link to connect to Tobii Studio:
 +
https://gitlab.socsci.ru.nl/h.voogd/tobiiclearviewtriggerapipython3
 +
the tobii-research package is installed on our lab computers.
  
If you have any questions about this, come to TSG.
+
=== For Tobii Pro Lab ===
 +
Tobii-research is installed on our lab computers. Titta (https://github.com/marcus-nystrom/Titta) is not working on a two-computer-system.
  
Also see: https://github.com/psychopy/psychopy/releases/tag/1.85.0
+
==Usage==
 +
===VirtualEnv===
 +
Some of the packages that are installed in the steps above, make it possible to make use of VirtualEnvs. A virtual environment is a Python environment such that the Python interpreter, libraries and scripts installed into it are isolated from those installed in other virtual environments, and (by default) any libraries installed in a “system” Python, i.e., one which is installed as part of your operating system.
  
==== Version History ====
+
If you want to use virtualenvs on your on computer, In ''System| Advanced system settings | Environment variables'', make a new system variable with name '''WORKON_HOME''' and value ''C:\Users\Public\Envs\''.
 +
And make a new system variable with name: '''PROJECT_HOME''' and value ''C:\Users\Public\Projects''. Your virtualenvs will now be stored in ''C:\Users\Public\Projects'' and projects in ''C:\Users\Public\Projects''. These are also the places where virtualenvs and projects are stored on the labcomputer.
  
For version history and bug fixes please check here: http://www.psychopy.org/changelog.html
+
Open a command window with administrator rights and type:<br>
 +
'''workon'''  to see a list of existing virtualenvs.<br>
 +
'''workon <virtualenvname>''', where <virtualenvname> is the name of the virtualenv you want to use.<br>
 +
'''mkvirtualenv <virtualenvname>''' to create a new and empty virtualenv.<br>
 +
'''mkvirtualenv -p=37 <virtualenvname>''' to create a new and empty virtualenv that uses the installed Python3.7.6.<br>
 +
'''mkvirtualenv -p=36 <virtualenvname>''' to create a new and empty virtualenv that uses the installed Python3.6.8.<br>
 +
'''mkvirtualenv -p=37 --system-site-packages <virtualenvname>''' to create a new virtualenv that uses the installed Python3.7 and its site-packages.<br>
 +
'''rmvirtualenv <virtualenvname>''' to remove the virtualenv with name <virtualenvname>.<br>
 +
'''deactivate''' to return to the defaults.
 +
<br>
  
==== Google Mailing list ====
+
If you need a package that is not installed on our labcomputer, contact TSG, so that we can decide to add it to our standard installation, or to install it in a separate virtualenv. Do '''not''' use ''pip install'' and install anything in an existing virtualenv. Unless it is your own virtualenv. This might interfere with existing packages and might mess up other peoples projects. Instead, make your own virtualenv and install it there (use '''mkvirtualenv''' to create it, use '''workon''' to activate it, then use '''pip''' to install packages into your own virtualenv). Also, make a backup of your virtualenv, since when the labimage is updated, the newly created virtualenvs will be gone.
  
For various information please click here: https://groups.google.com/forum/#!forum/psychopy-users
+
=== Spyder ===
 +
Spyder (Scientific Python Development Environment) is an IDE for Python. It can be run from a command prompt. If you want to use Spyder in the default Python environment, you can just type '''Spyder''' from the command prompt. If you want to use Spyder from a virtualenv, type '''workon <name of the virtualenv>''' and then type '''Spyder3'''. If you have created your own virtualenv, make sure that Spyder is installed.
  
==== GitHub Repository ====
+
=== PyCharm ===
 +
PyCharm is installed on our labcomputers. It is a Python IDE. In the lowerright corner, it will display its current Python environment. By clicking on that name, you can change the interpreter and choose from the existing virtualenvs that PyCharm knows. Or you can add your own virtualenv. <br><br>
 +
[[File:PycharmInterpreters.png|thumb|none|PycharmInterpreters]]
  
For requests / bug report / issues click here: https://github.com/psychopy/psychopy
+
=== Batch files ===
 +
If you are working from a virtualenv, other than the default, and you don't want to open a command window, type '''workon <virtualenv>''' and type '''python <myscript.py>''' every time, you might want to make a batch file. Create a text file, type:<br>
 +
'''call workon <virtualenv>'''<br>
 +
'''python <myscript.py>'''<br><br>
 +
Save the file into the folder where your script is, but change the extension from ''.txt'' to ''.bat'', for example, save the file as ''startmyscript.bat''.

Latest revision as of 14:16, 20 August 2024

Psychopy
Psychopy Logo.png
Development statusActive
Written inPython
Downloads
* MainCode for Template / Working Example
Manuals

PsychoPy is an alternative to Presentation, e-Prime and Inquisit. It is a Python library and application that allows presentation of stimuli and collection of data for a wide range of neuroscience, psychology and psychophysics experiments. When used on DCC computers PsychoPy is guaranteed to be millisecond accurate.

Installation

We recommend to use a modern 64-bit version of Python. In our labs, we currently have Python 3.8.10 64 bits installed. Psychopy recommends Python 3.8.10.

Check our gitlab server https://gitlab.socsci.ru.nl/tsg/psychopy2024.1.0install

For Pavlovia users

If you want to upload experiments to Pavlovia, you will need to install Git-2.17.1-64-bit.exe using these instructions: GitInstall.docx. Then, in System| Advanced system settings | Environment variables, add the folder where git-daemon.exe is, to the PATH variable. Usually, that folder is named: 'C:\Program Files\Git\mingw64\libexec\git-core'.

Lab computer versioning

A default version of Psychopy has been installed in the root of the Python3.8.10 64-bit version. This is also the default version when 'psychopy' is typed from the command prompt. It is also the default that opens when a .py file is double-clicked. It also can be started by clicking the appropriate icon on the desktop. One in a while, the default version is upgraded to a newer version. The older version is then still available in a virtualenv.


When your script fails to load in Psychopy, because you need packages that are not installed on our labcomputers, please contact TSG.

On the labcomputer, there is support for Spyder, PyCharm and Psychopy.

For SR-Research Eyelink users

Pylink is installed on our lab computers.

For SMI RED 500 and SMI HiSpeed Tower users

Include this file into your project: iViewXudp. This should work on both 64-bit and 32-bit Python 3 versions.

For Tobii Studio

Check this link to connect to Tobii Studio: https://gitlab.socsci.ru.nl/h.voogd/tobiiclearviewtriggerapipython3 the tobii-research package is installed on our lab computers.

For Tobii Pro Lab

Tobii-research is installed on our lab computers. Titta (https://github.com/marcus-nystrom/Titta) is not working on a two-computer-system.

Usage

VirtualEnv

Some of the packages that are installed in the steps above, make it possible to make use of VirtualEnvs. A virtual environment is a Python environment such that the Python interpreter, libraries and scripts installed into it are isolated from those installed in other virtual environments, and (by default) any libraries installed in a “system” Python, i.e., one which is installed as part of your operating system.

If you want to use virtualenvs on your on computer, In System| Advanced system settings | Environment variables, make a new system variable with name WORKON_HOME and value C:\Users\Public\Envs\. And make a new system variable with name: PROJECT_HOME and value C:\Users\Public\Projects. Your virtualenvs will now be stored in C:\Users\Public\Projects and projects in C:\Users\Public\Projects. These are also the places where virtualenvs and projects are stored on the labcomputer.

Open a command window with administrator rights and type:
workon to see a list of existing virtualenvs.
workon <virtualenvname>, where <virtualenvname> is the name of the virtualenv you want to use.
mkvirtualenv <virtualenvname> to create a new and empty virtualenv.
mkvirtualenv -p=37 <virtualenvname> to create a new and empty virtualenv that uses the installed Python3.7.6.
mkvirtualenv -p=36 <virtualenvname> to create a new and empty virtualenv that uses the installed Python3.6.8.
mkvirtualenv -p=37 --system-site-packages <virtualenvname> to create a new virtualenv that uses the installed Python3.7 and its site-packages.
rmvirtualenv <virtualenvname> to remove the virtualenv with name <virtualenvname>.
deactivate to return to the defaults.

If you need a package that is not installed on our labcomputer, contact TSG, so that we can decide to add it to our standard installation, or to install it in a separate virtualenv. Do not use pip install and install anything in an existing virtualenv. Unless it is your own virtualenv. This might interfere with existing packages and might mess up other peoples projects. Instead, make your own virtualenv and install it there (use mkvirtualenv to create it, use workon to activate it, then use pip to install packages into your own virtualenv). Also, make a backup of your virtualenv, since when the labimage is updated, the newly created virtualenvs will be gone.

Spyder

Spyder (Scientific Python Development Environment) is an IDE for Python. It can be run from a command prompt. If you want to use Spyder in the default Python environment, you can just type Spyder from the command prompt. If you want to use Spyder from a virtualenv, type workon <name of the virtualenv> and then type Spyder3. If you have created your own virtualenv, make sure that Spyder is installed.

PyCharm

PyCharm is installed on our labcomputers. It is a Python IDE. In the lowerright corner, it will display its current Python environment. By clicking on that name, you can change the interpreter and choose from the existing virtualenvs that PyCharm knows. Or you can add your own virtualenv.

PycharmInterpreters

Batch files

If you are working from a virtualenv, other than the default, and you don't want to open a command window, type workon <virtualenv> and type python <myscript.py> every time, you might want to make a batch file. Create a text file, type:
call workon <virtualenv>
python <myscript.py>

Save the file into the folder where your script is, but change the extension from .txt to .bat, for example, save the file as startmyscript.bat.