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