Installations
First of all, you need PsychoPy. See install instructions on psychopy.org.
I recommend using Spyder as code editor rather than Coder. You get code completion and in-app documentation which speeds up programming a lot! See install instructions below.
Enabling Spyder for PsychoPy on Windows
On windows, there are a number of options. My favourite option is to install Spyder into PsychoPy’s own python.
Now go to “Tools –> Preferences –> Run”, and tick “Execute in a dedicated Python interpreter” to make it easy to re-run the experiment without getting errors due to python being shut down when the psychopy module is unloaded.
As an alternative, you can install Spyder in it’s own distribution and hen “point it” to PsychoPy as described in the following. Spyder is pre-packaged in the python(x,y) package among others. Install that. If you use Windows, you need to make Spyder “aware” of PsychoPy by doing the following:
- Open Spyder –> Tools –> PYTHONPATH manager
- Add the following two paths (psychopy usually installs to C:\Program Files (x86)\PsychoPy2 on Windows) and do NOT click “synchronize”.[psychopy-folder]\Lib\site-package[psychopy-folder]\Lib\site-packages\psychopy[version].egg
- Now open Spyder and you should be able to run the following small script without errors:
from psychopy import *
Pros: If you want to use other editors or don’t want psychopy to be in your PYTHONPATH, you can simply load psychopy by adding the following to the top of your scripts:
import sys sys.path.append("[psychopy-folder]\Lib\site-package\PsychoPy[version].egg") sys.path.append("[psychopy-folder]\Lib\site-package") from psychopy import *
Enabling Spyder for PsychoPy on linux
I recommend using Spyder as code editor rather than Coder. You get code completion and in-app documentation which speeds up programming a lot! On Debian-based Linux (Ubuntu / Debian / Linux Mint etc.), just run the following in the terminal
sudo apt-get install spyder pylint pyflakes python-rope python-sphinx
Check that it works by running the following script in spyder:
from psychopy import *
Now go to “Tools –> Preferences –> Run”, and tick “Execute in a dedicated Python interpreter” to make it easy to re-run the experiment without getting errors due to python being shut down when the psychopy module is unloaded.
Enabling Spyder for PsychoPy on Mac
You can get it to work using the anaconda python distribution. Scroll down on this page to see install instructions. Also see comments below, where a user succeeded with Atom – an editor which has the same capabilities as Spyder.
To use iohub to register keyboard events you need to raise the privileges of the PsychoPy app. Do this by drag-dropping it into the Accessibility list like this.
Checking your hardware
After installing PsychoPy, open Coder –> demos –> timing –> timesByFrames.py and run it (press CTRL-R or the green man). It should show a distribution around 16.667 ms (if you’re running 60 Hz) with a narrow distribution, say from 16 to 17 ms and no dropped frames. If this doesn’t work, try updating the graphics card drivers by fetching the latest version from the vendor’s website.
If this doesn’t work either, try using a different computer. As a reminder: laptops and other systems with non-dedicated graphics- and video-cards are generally not suitable for psychophysics but may be still acceptable as a development environment.
Python tutorials
If you’re new to programming, prepare to spend 5-10 hours to familiarize yourself with it. This time will pay off great dividends. With a bit of programming skill you get access to a lot of useful tools and increase your coolness factor! I recommend CodeAcademy’s nice interactive introduction to Python (and programming in general): http://www.codecademy.com/tracks/python
If you’re acquainted with programming but don’t know Python, go through this concise introduction. Make sure to not just read it but to play around with it, changing values and creating new variables, testing if it works like you’d expect. I spend 2-3 hours getting through it myself initially though I was already experienced with MATLAB and PHP.
————————
Open Spyder –> Tools –> PYTHONPATH manager
Add the following two paths (psychopy usually installs to C:\Program Files (x86)\PsychoPy2 on Windows) and do NOT click “synchronize”
[psychopy-folder]\Lib\site-package
[psychopy-folder]\Lib\site-packages\psychopy[version].egg
Now open Spyder and you should be able to run the following small script without errors:
from psychopy import *
———————————–
I tried the following but spyder still can’t seem to import the psychopy module when called for. Worst still, I accidentally synchronized the paths before I chanced upon your site and since then, I cannot launch Spyder (Reset Spyder setting doesn’t work, it immediately terminates when launched) as long as Psychopy is installed on my Windows. Reinstalling both programs wouldn’t work as well. At the moment, I can only launch up Spyder when Psychopy is completely removed from my computer. Is there a way to fix this?
Best Regards,
Aaron
Wow, that sounds like a mess. I can’t think of a solution, unfortunately, other than making sure that absolutely everything is removed, including registry entries etc. It’s a long time since I ran Windows, so I can’t give specific directions. Ask Google 🙂
Jonas
Hi Jonas,
Thanks for throwing together some of this documentation. I am pretty experienced in MatLab and am looking to switch to Psychopy. Until this point I was having trouble getting Psychopy and Spyder to co-habit. Fortunately I found this site and everything is now working!!
Thanks again,
-Tim
Hello there,
This guide was really great for setting up my new windows computer, so thanks very much! In your post, you said that you hadn’t found a neat way with OSX yet. I have been using psychopy with Atom (a github text editor) for the last 8 months and have found it to be really great, so maybe you could try that (if you wanted) 🙂 I find it much better than using Psychopy itself, which is super frustrating!
Best
Christina.
Pingback: PsychoPy and the Tobii Python SDK | Vision Research Blog
Hello, I get the following error on spyder after adding the two paths:
C:\Program Files (x86)\PsychoPy2\Lib\site‑packages\IPython\kernel\__init__.py:13: ShimWarning: The `IPython.kernel` package has been deprecated. You should import from ipykernel or jupyter_client instead.
“You should import from ipykernel or jupyter_client instead.”, ShimWarning)
Traceback (most recent call last):
File “C:\Python27\lib\site‑packages\spyderlib\widgets\externalshell\start_ipython_kernel.py”, line 167, in
from IPython.kernel.zmq.kernelapp import IPKernelApp
File “C:\Program Files (x86)\PsychoPy2\Lib\site‑packages\IPython\kernel\__init__.py”, line 31, in
from ipykernel import comm, inprocess
ImportError: No module named ipykernel
Is there a way to solve this?
Thanks
If you’ve installed spyder + the scipy stack etc through anaconda, you can simply do (tested on win + linux, should work everywhere):
conda install -c CogSci pyglet psychopy
Hello Jonas,
Thank you for this very comprehensive website. I am trying to make PsychoPy2 work with Spyder3 on Windows (Python 3.5.2 |Anaconda 4.2.0 (64-bit)| (default, Jul 5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)]).
I followed your instructions and added “[psychopy-folder]\Lib\site-package” and “[psychopy-folder]\Lib\site-packages\psychopy[version].egg” to the PYTHONPATH, but I am still getting the “ImportError: No module named ‘psychopy'” when running the little import script.
I wonder if it’s that Spyder runs on Python 3.5 and not on Python 2.7? I did re-install both the newest PsychoPy Standalone and reset the settings for Spyder, but I get the same error message.
Any kind of help is appreciated, I am pretty new to PsychoPy and Spyder, but i would love to make it work.
Thank you very much,
Stefanie