Draft and probably crappy instructions for setting up PsychoPy to run under Anaconda

557 views
Skip to first unread message

Michael MacAskill

unread,
Jan 1, 2015, 1:33:29 AM1/1/15
to <psychopy-users@googlegroups.com>
Dear All,

Occasionally people have a need to run PsychoPy under a custom Python environment rather than via the standalone (not just for developers). This process is always a bit of a moving target and so our current online instructions for this are a bit out of date. I always get confused about this myself and end up reinventing the wheel each time, so thought I would circulate a draft step-by-step set of instructions. I never really understand what I’m doing in this process, so please correct any glaring (or minor) errors or omissions.

This was written in response to a specific request to run under 64 bit on OS X. I have no idea how much is in common with Windows, or if there are more or fewer problems with the 32 bit version. I guess Linux users already know what they are doing… I’m describing this in baby-steps because that is what I need for myself

It would be great if anyone out there could add to/correct this, and then we could update the developer instruction documents on the website. So I’m putting this up as a first draft:

(1) Download and install the relevant version (Python 2.7, Win/Mac, 32 vs 64 bit) of Anaconda from here: <http://continuum.io/downloads>

(2) Once it is installed, it should supersede the version of python that comes bundled with OS X. That is, if you go into a Terminal window and type “python”, it should launch the Anaconda version and not the system version. You can tell if this is the case by typing:

which python

This should yield a response like:
/Users/<yourUserName>/anaconda/bin/python

rather than the system standard like:
/usr/local/bin/python

Or type:

python --version

This should yield a response like:
Python 2.7.9 :: Anaconda 2.1.0 (x86_64)

Rather than the system standard like:
Python 2.7.5

The Anaconda installer does this by adding these lines to the file ~/.bash_profile

# added by Anaconda 2.1.0 installer
export PATH="/Users/<username>/anaconda/bin:$PATH”

So if you comment out that second line, you get back access to the system Python again if needed.

(3) The Anaconda installation of Python comes with a lot of the packages needed by PsychoPy. But there are a bunch of other dependencies that need to be added as well. Erik Kastman has helpfully automated a lot of the hassle of getting all of them by creating an “install recipe”. Anaconda comes with a good installation manager called conda, but you need to tell it how to find Erik’s recipe by typing this in the Terminal:

conda config --add channels https://conda.binstar.org/erik

And then:

conda install psychopy

NB this isn’t installing PsychoPy itself, but rather a bunch of dependencies upon which it relies.
There are still some quirks with them:
— The pyo sound library doesn’t seem to run under 64 bit. So trying to run an experiment from Builder might generate the error "No audio API found. Try installing pyo 0.6.8+, or pygame 1.8+” Assuming you don’t need sound, then a work-around for this is not to push the green “Run” button in Builder but instead the “Compile script” button. This will open the code in a window in Coder. You then need to edit the import line:
from psychopy import visual, core, data, event, logging, sound, gui

by deleting “sound” from the list. Then you can push the green run button in that Coder window to run your experiment. If you need sound, then you should be using the 32 bit version of Anaconda.

— There is also currently a version checking bug in the Pyglet library that means it won’t run under OS X 10.10. The bug has been fixed but not in the currently released version of Pyglet. So again, if you find Pyglet errors about that when trying to run PsychoPy, you will need to install the latest development version of Pyglet yourself from the Terminal:

pip install --upgrade http://pyglet.googlecode.com/archive/tip.zip

Pip is another install manager, which itself might need to be installed, e.g.

sudo easy_install pip

Or alternative means here: <http://stackoverflow.com/questions/17271319/installing-pip-on-mac-os-x>

(3) Now you actually need to install PsychoPy itself. You likely already have a nicely packaged-up version of PsychoPy in the standalone application. That can stay, and can still be used by simply double-clicking. But you now need to install a version that can be run from the command line under your Anaconda Python.

This is where there are differences between developing and wanting to run actual experiments. Developers generally just want the latest, usually unreleased version, to contribute changes to. This is the “master” branch. But people wanting to run an experiment will usually want a specific, released stable version. I *think* the way to do this would be to go to the PsychoPy GitHub website here <https://github.com/psychopy/psychopy> and then select a different release branch from the pop-up menu there (e.g. <https://github.com/psychopy/psychopy/tree/r1.80>)

If you are a developer, instructions on how to work with the git version control system and the PsychoPy GitHub website are here:
<http://www.psychopy.org/developers/repository.html>

But if you just want to download a specific version of the PsychoPy source to use in experiments, then I think you could just select the release branch you want and then click on the “Download Zip” button on the right hand side.

(4) Once the downloaded file is decompressed to a folder somewhere, finally you now have a version of PsychoPy which can be run under Anaconda. You have to explicitly point Python to run this PsychoPy application. It is perhaps best to do this by making a short alias so you don’t have to type paths all the time. Again, edit your bash_profile file by adding these lines, using the actual path to your PsychoPy folder:

export PYTHONPATH=~/path/to/psychopyFolder:$PYTHONPATH
alias pp64='pythonw ~/path/to/psychopyFolder/psychopy/app/psychopyApp.py'

Then just typing pp64 will launch PsychoPy Builder under Anaconda. The reason we run pythonw rather than python is some arcane requirement I can’t quite remember to do with a GUI toolkit used by PsychoPy.


*** Please reply with any suggestions or queries. Sam: if you try this process, let us know of any pitfalls ***

Mike














Samuel Mehr

unread,
Jan 1, 2015, 3:58:23 PM1/1/15
to psychop...@googlegroups.com
Dear Mike,

Thanks for this wonderful tutorial. I’ve gone through all the steps and have edited/added to the instructions below (my edits on lines beginning ****SM). Hopefully this is useful to you coming from a beginner Python user, and it seems from the posts on this forum that I’m not alone among the psychopy userbase!

The results: I’ve got PsychoPy running in Anaconda and my original copy running separately in the regular standalone python. Both run simple experiments just fine (ie, displaying 'hello world' text). But I haven’t yet been able to play videos — I get “AttributeError: ‘module’ object has no attribute ‘MovieStim2’” despite having downloaded and installed VLC 64-bit after installing Anaconda. Did I miss a step?

S

(1) Download and install the relevant version (Python 2.7, Win/Mac, 32 vs 64 bit) of Anaconda from here: <http://continuum.io/downloads>
****SM: On OS X, the Anaconda installer appears to be pretty sensitive to available processor power. To ensure that you don’t wait 45 minutes for the install, close all apps before running the installer.

(2) Once it is installed, it should supersede the version of python that comes bundled with OS X. That is, if you go into a Terminal window and type “python”, it should launch the Anaconda version and not the system version. You can tell if this is the case by typing: 
****SM: For python newbs like me, I would make this part of the instructions required. something like “Now, make sure Anaconda installed properly. Open a Terminal window and type…”

which python 

This should yield a response like: 
/Users/<yourUserName>/anaconda/bin/python 

rather than the system standard like: 
/usr/local/bin/python 

Or type: 

python --version 

This should yield a response like: 
Python 2.7.9 :: Anaconda 2.1.0 (x86_64) 
****SM: the latest version from continuum.io appears to be 2.7.8.

Rather than the system standard like: 
Python 2.7.5 

The Anaconda installer does this by adding these lines to the file ~/.bash_profile 

# added by Anaconda 2.1.0 installer 
export PATH="/Users/<username>/anaconda/bin:$PATH” 

****SM: Anaconda didn’t appear to add this to my bash_profile … in fact, I didn’t even have a .bash_profile file after installing Anaconda. I added this line below (see end of this page)

So if you comment out that second line, you get back access to the system Python again if needed. 

(3) The Anaconda installation of Python comes with a lot of the packages needed by PsychoPy. But there are a bunch of other dependencies that need to be added as well. Erik Kastman has helpfully automated a lot of the hassle of getting all of them by creating an “install recipe”. Anaconda comes with a good installation manager called conda, but you need to tell it how to find Erik’s recipe by typing this in the Terminal: 

conda config --add channels https://conda.binstar.org/erik 
conda install psychopy 
****SM: when asked whether to proceed, type y

# this isn’t installing PsychoPy itself, but rather a bunch of dependencies upon which it relies. 

****SM: this next stuff could all go to item (6) since it’s pertinent once psychopy is already running.

There are still some quirks with them: 
— The pyo sound library doesn’t seem to run under 64 bit. So trying to run an experiment from Builder might generate the error "No audio API found. Try installing pyo 0.6.8+, or pygame 1.8+” Assuming you don’t need sound, then a work-around for this is not to push the green “Run” button in Builder but instead the “Compile script” button. This will open the code in a window in Coder. You then need to edit the import line: 
from psychopy import visual, core, data, event, logging, sound, gui 

by deleting “sound” from the list. Then you can push the green run button in that Coder window to run your experiment. If you need sound, then you should be using the 32 bit version of Anaconda. 

— There is also currently a version checking bug in the Pyglet library that means it won’t run under OS X 10.10. The bug has been fixed but not in the currently released version of Pyglet. So again, if you find Pyglet errors about that when trying to run PsychoPy, you will need to install the latest development version of Pyglet yourself from the Terminal: 


Pip is another install manager, which itself might need to be installed, e.g. 

sudo easy_install pip 


(4) Now you actually need to install PsychoPy itself. You likely already have a nicely packaged-up version of PsychoPy in the standalone application. That can stay, and can still be used by simply double-clicking. But you now need to install a version that can be run from the command line under your Anaconda Python. 

****SM: this part is super important for my situation, and I suspect would also be for others who are running psychopy in a lab with multiple people sharing machines: taking a brief hiatus from the Anaconda install here and running an experiment in standalone psychopy runs just fine. To test this, I just ran the same experiment that plays a few images and videos. It ran without a hitch.

This is where there are differences between developing and wanting to run actual experiments. Developers generally just want the latest, usually unreleased version, to contribute changes to. This is the “master” branch. But people wanting to run an experiment will usually want a specific, released stable version. I *think* the way to do this would be to go to the PsychoPy GitHub website here <https://github.com/psychopy/psychopy> and then select a different release branch from the pop-up menu there (e.g. <https://github.com/psychopy/psychopy/tree/r1.80>) 

If you are a developer, instructions on how to work with the git version control system and the PsychoPy GitHub website are here: 

But if you just want to download a specific version of the PsychoPy source to use in experiments, then I think you could just select the release branch you want and then click on the “Download Zip” button on the right hand side. 

****SM: not clear here which version I would need to download — this should be rephrased for clarification. I just used the 1.81.03 zip.

(5) Once the downloaded file is decompressed to a folder somewhere, finally you now have a version of PsychoPy which can be run under Anaconda. You have to explicitly point Python to run this PsychoPy application. It is perhaps best to do this by making a short alias so you don’t have to type paths all the time. Again, edit your bash_profile file by adding these lines, using the actual path to your PsychoPy folder: 

****SM: may as well make this a standard location for OSX users. I used /Applications/PsychoPy2_Anaconda.

****SM: I didn’t already have a .bash_profile, so I made one, with instructions below // pls confirm that this is all appropriate — it seems to be working fine for me, but I don’t really know what I’m doing and am operating off several stackoverflow pages

(6) If you don’t already have a .bash_profile, in Terminal, type

touch ~/.bash_profile open ~/.bash_profile

This will open a blank text file in your default text editor. Then type…

export PATH=“~/anaconda/bin:$PATH” 
export PYTHONPATH=~/path/to/psychopyFolder:$PYTHONPATH 
alias pp64='pythonw ~/path/to/psychopyFolder/psychopy/app/psychopyApp.py' 

Save the file and close TextEdit. Then, back in Terminal, type

source ~/.bash_profile

to load the values without needing to reboot. Now, typing pp64 will launch PsychoPy Builder under Anaconda. The reason we run pythonw rather than python is some arcane requirement I can’t quite remember to do with a GUI toolkit used by PsychoPy. 

****SM: For OSX users, would make sense to make a little container that runs this code so pp64 can sit on the dock next to regular old 32-bit psychopy.

(a) open AppleScript Editor (/Applications or find it via Spotlight)
(b) in the main window, type:

tell application “Terminal”
activate
do script “pp64”
end tell

(c) hit Save, choose “Application” as the file format, and save it to /Applications
(d) if you’re in a lab with non-python users, at this point you can edit the icon, add the app to the dock, etc, for ease of use

****SM: (6) [everything from the notes above between (3) and (4)

****SM: (7) if you’re intending to play videos in your experiment, download 64-bit VLC (to replace 32-bit VLC), and do XYZ to make it work… I don’t have this working yet!

Michael MacAskill

unread,
Jan 3, 2015, 2:52:47 AM1/3/15
to psychop...@googlegroups.com
Hi Same,

Thanks for contributing back to those instructions. Details from someone doing this from scratch are exactly what is required.

Will look forward to further info on the VLC/moviestim front.

Cheers,

Mike


Samuel Mehr

unread,
Jan 3, 2015, 1:36:50 PM1/3/15
to psychop...@googlegroups.com
sure thing! so I still haven't been able to get VLC playing on my main machine. Now trying on a MacBook Air (specs below) and reporting my results... a few things:

(a) for some reason, this time Anaconda did create a ~/.bash_profile and add the PATH line: this didn't happen on my main machine, as I described above.
(b) before I installed Anaconda, I removed VLC from my computer (including its preferences folder) and installed a fresh copy of 64-bit, running it once to make sure the preferences populated.

Everything works fine ... except for videos, which give the same error message as before (note that I'm getting it both when running my own [poorly-written] scripts and also the MovieStim2 demo):

File "/Users/samuelmehr/SMdocs/LAPS/stim/psychopy/LAPS.py", line 86, in <module>
    calibration = visual.MovieStim2(win=win, name='calibration',units='pix', 
AttributeError: 'module' object has no attribute 'MovieStim2'

Sol, I think you had mentioned having already tested videos in a version of psychopy that used anaconda & vlc-64bit? Did you run into this problem?

thanks!
Sam

specs on other computer:
Model Name: MacBook Air
Model Identifier: MacBookAir4,1
Processor Name: Intel Core i7
Processor Speed: 1.8 GHz
Number of Processors: 1
Total Number of Cores: 2
L2 Cache (per Core): 256 KB
L3 Cache: 4 MB
Memory: 4 GB
Boot ROM Version: MBA41.0077.B11
SMC Version (system): 1.74f4
Chipset Model: Intel HD Graphics 3000
Type: GPU
Bus: Built-In
VRAM (Total): 384 MB
VRAM (Dynamic, Max): 10
Vendor: Intel (0x8086)
Device ID: 0x0116
Revision ID: 0x0009

Jon Peirce

unread,
Jan 4, 2015, 2:24:14 PM1/4/15
to psychop...@googlegroups.com
Sam, I've just been playing with conda (I use miniconda rather than anaconda but I doubt that makes a difference) and it's been playing the movies just fine. Maybe you have vlc but not opencv? Or maybe your vlc is the wrong architecture for the python you're using; if you're using 32bit conda then you need 32bit vlc installed instead.

Could you open python and do:
import opencv
import vlc
and let us know what happens?

Jon
--
You received this message because you are subscribed to the Google Groups "psychopy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to psychopy-user...@googlegroups.com.
To post to this group, send email to psychop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/psychopy-users/b55aa5d3-1054-4da5-aceb-357f97c10e0e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Samuel Mehr

unread,
Jan 4, 2015, 2:29:09 PM1/4/15
to psychop...@googlegroups.com
Thanks Jon — it looks like I have neither... I assumed that by downloading & installing VLC 64bit this would be taken care of, but apparently not! How do I install them?

Sam-Macbook-Air:~ samuelmehr$ python
Python 2.7.9 |Anaconda 2.1.0 (x86_64)| (default, Dec 15 2014, 10:37:34) 
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
>>> import opencv
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named opencv
>>> import vlc
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named vlc

--
You received this message because you are subscribed to a topic in the Google Groups "psychopy-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/psychopy-users/xUVep6tB2TY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to psychopy-user...@googlegroups.com.

To post to this group, send email to psychop...@googlegroups.com.

Jon Peirce

unread,
Jan 4, 2015, 2:37:37 PM1/4/15
to psychop...@googlegroups.com
Wait, my bad, they should be imported with
    import cv2
    from psychopy.visual import vlc

try that instead

Samuel Mehr

unread,
Jan 4, 2015, 2:39:52 PM1/4/15
to psychop...@googlegroups.com
gotcha — looks like I have VLC working but not opencv...?

>>> import cv2

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named cv2
>>> from psychopy.visual import vlc
>>>

Jon Peirce

unread,
Jan 4, 2015, 2:42:44 PM1/4/15
to psychop...@googlegroups.com
Maybe that wasn't included in Erik's conda recipe but it can be added separately at the terminal using

conda install opencv

Try that and try the import again

Samuel Mehr

unread,
Jan 4, 2015, 2:50:01 PM1/4/15
to psychop...@googlegroups.com
perfect, thanks!! everything is running now, and even on my little crap laptop the 60fps videos are already smoother than they were in 32bit. I'll test later on in lab with a more substantial machine and report back.

Reply all
Reply to author
Forward
0 new messages