Tuesday, June 28, 2011

Installing Spyder on OS X 10.6.7 (Snow Leopard) on a MacBook Pro Core i7 (64 bit)

Note: see http://notcomputing.blogspot.com/2013/02/spyder-and-ipython-in-os-x-mountain-lion.html for notes on installing Spyder and IPython in OS X Mountain Lion.  Those newer notes could probably also be adapted to work with earlier versions of OS X.  The steps in the new set of notes are definitely easier than those in this older version.

Installing Spyder on OS X 10.6.7 (Snow Leopard) on a MacBook Pro Core i7 (64 bit)

Spyder is MATLAB-like GUI for a number of scientific computing packages written in Python.

Here is a rough outline of what I did to get Spyder working (specifically: Spyder 2.0.12). Over the course of installing Spyder, I came across several helpful tutorials and forum discussions. The links for these are given at the bottom.

Steps

1. Install the academic version of the 64-bit Enthought Python Distribution (EPD64) for OS X (epd-7.0-2-macosx-x86_64 for me). This package is available from enthought.com, but it requires an academic email address in order to be sent the download link.

This distribution came with Python 2.7 and many Python packages including pyflakes, sphinx, numpy, scipy, matplotlib, and IPython. EPD installed Python in a somewhat non-obvious place for me:

/Library/Frameworks/EPD64.framework/Versions/7.0/lib/python2.7

2. Install GCC compilers

I didn't really do anything for this step because I had already done it earlier before trying to install Spyder, but I saw it listed on another tutorial so I include it here. My OS X installation disc came with Xcode (3.2.3) already on it in the "Optional Installs" folder. Xcode was not installed by default when I received the computer. I installed it myself from the disc. Xcode provides the necessary compilers. Supposedly, Xcode can also be downloaded for free from the Apple Developer Connection website, but I didn't figure out how to do that before realizing I already had access to Xcode on the installation disc.

3. Install QtSDK

Qt is a cross-platform application and user interface framework. It is used to power the Spyder interface.

I downloaded the QtSDK OS X installer (Qt_SDK_Mac64_offline_v1_1_2_en.dmg for me) from Nokia at qt.nokia.com/downloads. I then just ran the installer and left every setting with the default value.

4. Install SIP

SIP is a program/module that helps interface Python with C/C++ libraries. It is a dependency of PyQt.

I downloaded the current version of SIP for OS X (sip-4.12.3.tar.gz) from http://www.riverbankcomputing.co.uk/software/sip/download. I saved it in the directory ~/Library/Spyder/ within my user directory. I then went to this directory in the terminal and extracted the files:

tar -xf sip-4.12.3.tar.gz

At this point, I changed directories to the one created by tar and tried to configure SIP but encountered an error ("Error: SIP requires Python to be built as a framework"). Looking around on the web, I found a discussion that recommended editing siputils.py file in the extracted SIP directory to change "Python.framework" to "EPD64.framework". After this (in the same terminal window as before -- in the sip-4.12.3 folder) I entered the commands:

python configure.py -d /Library/Frameworks/EPD64.framework/Versions/7.0/lib/python2.7/site-packages
make
sudo make install

In the first command, the path following the "-d" flag was the location of the site-packages folder of EPD64's Python installation. This location was chosen because Python has access to it on the PYTHONPATH.

5. Install PyQt

PyQt is a set of Python modules that interfaces between Qt and Python.

I downloaded the current version of PyQt for OS X (PyQt-mac-gpl-4.8.4.tar.gz) from http://www.riverbankcomputing.co.uk/software/pyqt/download. As with SIP, I saved it in the directory ~/Library/Spyder/ within my user directory. I then went to this directory in the terminal and extracted the files:

tar -xf PyQt-mac-gpl-4.8.4.tar.gz

I then moved to the PyQt-mac-gpl-4.8.4 folder and tried to configure PyQt as I had done with SIP using:

python configure.py -d /Library/Frameworks/EPD64.framework/Versions/7.0/lib/python2.7/site-packages

but I encountered the following error:

"Error: Make sure you have a working Qt v4 qmake on your PATH or use the -q argument to explicitly specify a working Qt v4 qmake."

I searched around with Finder for qmake and found two copies of it.... I just picked one and tried it:

python configure.py -q /Users/willshanks/QtSDK/Desktop/Qt/473/gcc/bin/qmake -d/Library/Frameworks/EPD64.framework/Versions/7.0/lib/python2.7/site-packages

generating the error:

"Error: Qt has been built as static libraries so either the -g or -k argument
should be used."

Finally I tried:

python configure.py -q /Users/willshanks/QtSDK/Desktop/Qt/473/gcc/bin/qmake -d/Library/Frameworks/EPD64.framework/Versions/7.0/lib/python2.7/site-packages -g

which did the trick. I followed this up with:

make
sudo make install

These commands generated a ton output in the terminal window and took several minutes to complete.

6. Install rope and pylint

These two packages are recommended/optional for Spyder and not included in EPD64. I downloaded pylint (pylint-0.23.0.tar.gz) from http://pypi.python.org/pypi/pylint and rope (rope-0.9.3.tar.gz) from http://rope.sourceforge.net/ into my ~/Library/Spyder/ directory. As above, I extracted them with tar -xf and in each case ran

sudo python setup.py install

from within the extracted folder. PyLint also generated a ton of output to the terminal including some "Syntax errors" but appeared to work for the most part (I am not sure how to test for its functionality yet).

7. Install Spyder

Finally, I downloaded Spyder (spyder-2.0.12.zip) to my ~/Library/Spyder directory from http://code.google.com/p/spyderlib/downloads/list. I unzipped this and moved to the spyder-2.0.12 directory in the terminal and entered the command:

sudo python setup.py install

8. Create Spyder launcher shortcut

Spyder should now be able launchable simply by typing "spyder" into a terminal window. Alternately, you can create a click-able icon using AppleScript. I just put:

do shell script "/Library/Frameworks/EPD64.framework/Versions/7.0/bin/spyder"

into AppleScript Editor and saved the file as an app. This app could then be clicked to launch Spyder.

Because I am particular about these things, I wanted my Spyder app to have the Spyder icon. To make this the case, I opened the svg file ~/Library/Spyder/spyder-2.0.12/spyderlib/images/spyder.svg that came with the Spyder zip file in InkScape and exported it as a 512 pixel wide png file. I then dragged this png file into Icon Composer (which was located in /Developer/Applications/Utilities) and produced a .icns file. I then downloaded Icon Droplet from http://download.cnet.com/IconDroplet/3000-2193_4-82563.html and ran it on the .icns file (not sure if this was really necessary). I then renamed this file applet.icns and saved it in the Resources folder of the Spyder app. This produced the Preview icon for the Spyder app. I then opened "Get Info" on the Spyder app, highlighted the Preview icon in the upper left, and pressed Delete. The icon then changed to the new Spyder icon. I am not sure if all of these steps were necessary or if some of them could have been skipped. I tried various iterations of these steps but I did not restart OS X in between -- that might have been needed for the icon to be updated everywhere.

To do: I haven't tested all of Spyder's functionality so I am not positive that everything is set up properly. Additionally, it would be nice to find a way to run Spyder without opening to "black box" exe icons in the dock.

Links

General installation of PyQt and Spyder:

http://code.google.com/p/spyderlib/wiki/Installation
http://works13.com/blog/mac/howto-install-spyder-1-x-on-mac-os-x-with-64bit-python.htm
http://blog.oak-tree.us/index.php/2010/05/27/pyqt-snow-leopard
http://www.oak-tree.us/blog/index.php/2009/05/12/pyqt-mac

Modifying SIP installation for EPD64 framework:
http://comments.gmane.org/gmane.comp.python.epd.user/138

Suggestion to NOT modify anything for PyQt, just add the -q and -g flags as described above:
(when trying to debug the errors with PyQt, I initially saw suggestions of modifying the PyQt setup files in a similar fashion to the way the SIP file was modified)
https://mail.enthought.com/pipermail/epd-users/2011-March/000337.html

Creating custom icons in OS X:
http://paulstamatiou.com/how-to-create-an-os-x-icon-from-a-vector-graphic
http://paulstamatiou.com/how-to-quickie-change-os-x-icons
https://discussions.apple.com/thread/3069882?start=0&tstart=0