running psychopy scripts with the console / terminal on Mac OS X

3,556 views
Skip to first unread message

Bartholdy

unread,
Jan 29, 2011, 4:14:48 PM1/29/11
to psychopy-users
Dear psychopy-users,

I have a problem installing psychopy on my mac
(MacBook Pro i5, Mac OS X 10.6.6 - xcode tools installed).

I would like to use psychopy from the console / terminal (not the GUI-
version).
So I installed Python, gcc and all the dependencies needed via
macports
( sudo port install py25-psychopy ).

This took several hours, crashed one or two times but finally finished
successfully (I think).

Now, when I try to run python code with psychopy, it still says
"ImportError: No module named psychopy".

What am I doing wrong?



--------------------------------------------------------

admins-MacBook-Pro:~ admin$ python
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from psychopy import visual, event, core, log
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named psychopy
>>>

Jeremy Gray

unread,
Jan 29, 2011, 4:51:16 PM1/29/11
to psychop...@googlegroups.com
Hi Bartholdy,

my guess is that you need to tell your macports version of python
where to find psychopy, by adding a Psychopy.pth file somewhere. I use
mac 10.6.6 and run experiments from the command line (terminal).

I use the the "Enthought python distribution" version of python, and
so for me this means making a file named Psychopy.pth in the directory
/Library/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages/
The file is plain text, and contains a single line, which is the
location (directory) of my psychopy source code.

about a week ago I installed the EPD python + psychopy on a
colleague's computer. it it took maybe 10-15 min, no need for gcc or
xcode.

best,

--Jeremy

> --
> You received this message because you are subscribed to the Google Groups "psychopy-users" group.
> To post to this group, send email to psychop...@googlegroups.com.
> To unsubscribe from this group, send email to psychopy-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/psychopy-users?hl=en.
>
>

Emily

unread,
Jan 29, 2011, 6:46:05 PM1/29/11
to psychopy-users
Hi Bartholdy,

I switched from a PC to a Mac recently and had a real problem getting
everything integrated, only *just* now getting it to work just how I
wanted. I did the overhaul method, which may be something to try if
Jeremy's suggestion doesn't work. This took an evening, but it works
beautifully now. Here's my steps:

1. Remove everything except your system python. This can be a pain-
you need to dig into /Library/Frameworks/Python.framework/Versions and
delete everything except the system one (probably Python 2.5). Also
delete MacPython (or whatever is simlarly named) folder in
Applications, along with all other attempts (I had an Endthought
version installed, some other version of python installed, and one
installed through MacPorts). If you have a standalone version of
Pyschopy, you can leave that if you want.

The idea here is that you want just two Pythons -- the system version
and the one you will end up using. If there are duplicates beyond
that, it may cause confusion when installing dependencies or calling
python.

2. Go to here:
http://www.python.org/download/releases/2.6.6/ (and not the regular
download page)

Get the disk image installer and install. 2.6 is not the most recent
version of python -- however, I chose this version because it differs
from my system python. For example, if the system python is 2.5, get
2.6 (it works will with PyschoPy, not so sure about 2.7). That way,
you can select your dependencies later to run with 2.6 and you won't
have to worry about them getting installed on the system python 2.5.

3. From that point, usually paths are set correctly so that running
python from the command line should point to the latest one. If it
doesn't, log out and log in. If that still doesn't work, run the
update shell profile .command file in the Python folder inside
applications. (You should probably restart in any case...). To test
your versions, on the cmd type: 'type -a python'

You should get something like this:

python is /Library/Frameworks/Python.framework/Versions/2.6/bin/python
python is /usr/bin/python
python is /usr/local/bin/python

The top one and bottom one here are the same (you can check by just
typing in the path and looking at the version information when the
python environment starts). The middle on is the system version.

When you type 'python' alone to the command line, you should enter the
2.6 environment because it's the most current version. If when you
type it, you're still getting the system python, you can switch it
using this:

defaults write com.apple.versioner.python Version 2.6


4. Now, from here on, your first resource for installing packages
should be easy_install: http://pypi.python.org/pypi/setuptools.
Download the setuptools egg for your version and run it like a shell
script in whatever directory to which it downloaded.

sh setuptools-0.6c11-py2.6.egg

5. Now, to install something you can run:

easy_install [newdependency]
(You may have to add easy_install to your path, I can't remember where
it lives. You may also have to use sudo.)

That makes most package installations easy. For other packages, the
usual (disk image installer) approach should work, just make sure you
haven't set anything in your PYTHONPATH that could cause problems and
that you run the desired version of python when running this
installer.

6. Download all the dependcies listed on the PyschoPy installation
page (under the heading Dependencies) using their Disk Image
Installers (some might work with easy_install now, but to be safe, I
made sure to download the versions of these dependencies specifically
for 2.6):

• numpy (version 0.9.6 or greater)
• scipy (version 0.4.8 or greater)
• pyglet (version 1.1 or greater)
• pygame (for playing sounds. Must be version 1.8 or greater)
• wxPython (version 2.8 or greater)
• matplotlib (for plotting stuff)
• lxml (needed for printing saving builder experiment files)

(I recommend keeping all the .dmg /egg files you downloaded in a
directory for easy of installation on other Macs or your own if
something happens later).

Python Imaging Library and finally PscyhoPy should be installed with
easy_install.

easy_install PIL
easy_install psychopy

7. You're done! To test your PsychoPy set up, type python and then:

from psychopy import visual,core,gui

etc.

This should start a 'python launcher', which is how your experiments
will run now.


Good luck and let me know if you have any questions,

Emily

Bartholdy

unread,
Jan 29, 2011, 8:52:19 PM1/29/11
to psychopy-users
Wow,

thanks Jeremy & Emiliy for the quick and great help!

I have to say ... my system is now pretty messed up.
I have a lot of different python versions installed (over macports,
the dmg, Enthought) ... don't know if I will ever be able to clean
this up ..

However ... I finally tried your way Emily.

And it really got me a step closer!

My (perhaps) last problem is scipy ... I already tried to install
different versions (0-1.9.0rc1, 0-2.9.0rc1, 0-3.9.0rc1, 0-4.9.0rc1) ..
but still it gives me the following message:

>>> from psychopy import visual, event, core, log
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.6/site-packages/PsychoPy-1.63.01-py2.6.egg/
psychopy/visual.py", line 8, in <module>
from psychopy import core, ext, log, preferences, monitors, event
File "/Library/Python/2.6/site-packages/PsychoPy-1.63.01-py2.6.egg/
psychopy/monitors/__init__.py", line 6, in <module>
import calibTools
File "/Library/Python/2.6/site-packages/PsychoPy-1.63.01-py2.6.egg/
psychopy/monitors/calibTools.py", line 20, in <module>
import scipy.optimize as optim
ImportError: No module named scipy.optimize
>>> Terminated



thanks for the great help so far!
If you have any suggestions on how to properly set up scipy - please
let me know!



P.S.: it seems like I can run psychopy only in 32 bit
(so I used export VERSIONER_PYTHON_PREFER_32_BIT=yes before typing
python into the terminal)
do you know how I can make that the standard way of opening python via
"python" in the terminal?

Bartholdy

unread,
Jan 29, 2011, 10:03:36 PM1/29/11
to psychopy-users
Ok, now I tried to install scipy with the superpack_10.6_2011.01.13.

now scipy is found, but I get these error messages:

admins-MacBook-Pro:~ jorg$ python
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from psychopy import visual, event, core, log

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.6/site-packages/PsychoPy-1.63.01-py2.6.egg/
psychopy/visual.py", line 8, in <module>
from psychopy import core, ext, log, preferences, monitors, event
File "/Library/Python/2.6/site-packages/PsychoPy-1.63.01-py2.6.egg/
psychopy/monitors/__init__.py", line 6, in <module>
import calibTools
File "/Library/Python/2.6/site-packages/PsychoPy-1.63.01-py2.6.egg/
psychopy/monitors/calibTools.py", line 20, in <module>
import scipy.optimize as optim
File "/Library/Python/2.6/site-packages/scipy-0.10.0.dev_20110113-
py2.6-macosx-10.6-universal.egg/scipy/optimize/__init__.py", line 7,
in <module>
from optimize import *
File "/Library/Python/2.6/site-packages/scipy-0.10.0.dev_20110113-
py2.6-macosx-10.6-universal.egg/scipy/optimize/optimize.py", line 28,
in <module>
from linesearch import \
File "/Library/Python/2.6/site-packages/scipy-0.10.0.dev_20110113-
py2.6-macosx-10.6-universal.egg/scipy/optimize/linesearch.py", line 1,
in <module>
from scipy.optimize import minpack2
ImportError: dlopen(/Library/Python/2.6/site-packages/
scipy-0.10.0.dev_20110113-py2.6-macosx-10.6-universal.egg/scipy/
optimize/minpack2.so, 2): Symbol not found: _dcsrch_
Referenced from: /Library/Python/2.6/site-packages/
scipy-0.10.0.dev_20110113-py2.6-macosx-10.6-universal.egg/scipy/
optimize/minpack2.so
Expected in: flat namespace
in /Library/Python/2.6/site-packages/scipy-0.10.0.dev_20110113-py2.6-
macosx-10.6-universal.egg/scipy/optimize/minpack2.so
>>>

Emily Ward

unread,
Jan 30, 2011, 12:38:11 AM1/30/11
to psychop...@googlegroups.com
I had the same error and started to install superpack.... but it
seemed really bulky so I figured I was better just trying to figure
out what was wrong with scipy. FYI, I have
scipy-0.8.0-py2.6-python.org.dmg installed.

From your errors, it looks like you're GCC version is 4.2... but scipy
needs GCC 4.0. I think you can fix this typing by the following:

$ ln -s /usr/bin/g++-4.0 g++
$ ln -s /usr/bin/g++-4.0 c++

This (soft) links your g++/c++ versions to g++4.0. I don't entirely
remember if this is the only thing that I did to fix it so it may not
be sufficient. Try restarting after this and see if you have the same
problem.

As for running pyschopy as 32-bit by default, I'd add:

export VERSIONER_PYTHON_PREFER_32_BIT=yes

to your .bashrc file (if you're running in the regular "bash" shell).

The rc files are worth looking up and using a lot if you don't
already, but you can find it as follows.

[current path]$ cd
[/]$ open .bashrc

Add that variable to the file, save it, and then to update:
[/]$ source .bashrc


Good luck,

Emily

Jeremy Gray

unread,
Jan 30, 2011, 11:09:07 AM1/30/11
to psychop...@googlegroups.com
thanks Emily, I've learned a few things! I'm sure that your detailed
instructions will be useful to have in the archive.

still, I suspect that for most people who want to run from the command
line, unless they have a reason not to do so it will be easier to do:

[0. if needed: uninstall any versions of python that you have
personally installed. don't touch your system version. if you have a
stand alone version of psychopy, you don't need to worry about it,
fine to leave it as is.]

1. download & install the EPD 32-bit (not 64-bit) version of python
2.6 (from http://www.enthought.com/products/edudownload.php ) -- its
just a typical GUI click-through install, very easy.

2. open a new terminal window, type 'python' and it should show that
the EPD version is the one that is now on your regular user path:
[gray-matter:~] jgray% python
Enthought Python Distribution -- http://www.enthought.com
Version: 6.2-2 (32-bit)

3. from the command line, type 'easy_install psychopy', and once it
completes you should be good to go. start python interactively, and
type 'import psychopy' -- no error message means all is well.

4. if / when you need other packages, you can do things like
'easy_install pyaudio' to make those available to psychopy

I did this about 10 days ago for a colleague on a mac, no need to
wrangle with with gcc, .bashrc, sudo, versions of scipy, etc.

if you have had previous versions of python, you need to make sure
that your path variable no longer contains pointers to old versions of
python (or at least: that they are not ahead of a pointer to the new
version). typing 'python' at the command line should tell you
definitively which version is found. for me on XP, it was placing the
new pointer at the end of my path variable, so I had to manually edit
the path so that the new python would be found and used.

I think this should more or less work on mac, windows, and linux.

--Jeremy

Zarrar Shehzad

unread,
Jan 30, 2011, 12:49:48 PM1/30/11
to psychop...@googlegroups.com
Just to add to the discussion. After installing python and the prereqs (like Jeremy mentioned the enthought route is so much easier), there are two things you might find useful.

First, I like to use pip instead of easy_install in part since it keeps a better record of what is installed. You can do 'easy_install pip' and then 'pip install psychopy'. Now if you were to do 'pip search psychopy' it would show you the entry for psychopy as well as what version you have installed and the latest version that exists. You can upgrade like so 'pip install psychopy --upgrade'.  Also I am not sure if this has been mentioned but you might consider using ipython as your command-line interface (pip install ipython).

Second, if you have multiple versions of python installed and they are roughly in the same location you can use python_select or pythonselect to switch between them. (pip install pythonselect or easy_install python_select).

Cheers
Zarrar

Bartholdy

unread,
Jan 31, 2011, 12:10:03 PM1/31/11
to psychopy-users
thanks for the great help!

I managed to get it working now with EPD 32-bit.
The problem was that I use different user accounts (a normal user and
an administrator account).
And the .bash_profile files for the two users linked to two different
python versions.

Now I managed to install all the packages with the admin-user account
for Python 2.6.6 and were able to make sure that the normal user also
loads Python 2.6.6 via the python command
(and not one of the four other versions I installed over the last
couple of days ...).


thanks again!
Without your help I think I would have gone crazy by now ...
Reply all
Reply to author
Forward
0 new messages