Python vs. Mac OSX vs. Unix

Apple OSX Snow Leopard (10.6) includes three different versions of Python, a programming language needed for a course I was taking on image processing. The course specified Python 2.7 plus the package OpenCV. Various sections of OSX need 2.4, 2.5 or 2.6; my GIS package QGIS needs 2.6 and is partially disabled without it.

Given the course requirement, I installed Python 2.7 from, then went looking for OpenCV. After two weeks of consulting on half a dozen forums (including OpenCV's of course), I was forced to the conclusion that no one has found a way to install OpenCV with the Python 2.7 on OSX. Homebrew and MacPorts both claimed they could with their pythons; since I already had MacPorts for WINE, a Windows port, I installed their Python27+numpy+scipy+opencv.

Installation went fine, but nothing worked. It seems, from lengthy discussions on the MacPorts forum and others, that the python takes over so much of OSX with symlinks and such that the MacPorts python is effectively broken, shut out of all OSX linkages. QGIS was crippled because its Python 2.6 was hidden from it - a disaster for me. And, OpenCV, and my course with it, were dead in the water.

Here's what it took me to recover. All of it had to be done from an administrator account with a broadband internet connection. (I have DSL, about 4 MHz, but the Apple site was always slower than that.)

  1. backup everything
  2. delete the entire /opt directory (MacPorts stuff, Apple doesn't use it)
  3. search the entire disk for "python27" and for "2.7"; delete everything that has anything to do with python
  4. reinstall OSX along with Xcode from the Apple disk - it's scary but it did leave all user files and apps intact and working
  5. update OSX online - it took over 1 GB in my case

At this point, after at least 5 hours with my computer working non-stop, I had a solid OSX back, with no python-site Python, and all my apps were working. Whew! (took a break)

Download the latest version of Xcode for Snow Leopard (3.2.6) plus IOS SDK (4.3) from the Apple site - 4 GB, it took me 5 hours. For all except the current OSX, an Apple Developer account is needed to get it - it's free but separate from an AppleID. Install in the usual way. Download Java Developer for Snow Leopard (10.6); install it. Update OSX online again - another hour+.

Now, after 9 hours, my system was supposed to be ready for MacPorts. Download it and install as directed (less than an hour).

Since I need it for a few old Windows programs, install WINE next - it needs to install some sections of MacPorts python. Following directions on the WINE site:

echo export PATH=/opt/local/bin:/opt/local/sbin:\\$PATH$'\\n'export MANPATH=/opt/local/man:\\$MANPATH | sudo tee -a /etc/profile
if [ `sysctl -n hw.cpu64bit_capable` -eq 1 ] ; then echo "+universal" | sudo tee -a /opt/local/etc/macports/variants.conf; else echo "not 64bit capable"; fi
sudo port install wine

The first install crashed - something (probably the Xcode SDK) had already installed a module a different way than MacPorts accepts. Follow directions given (three long Terminal commands that I didn't write down) to patch MacPorts, then reinstall WINE; it worked the second time. WINE works again with my apps too. Time 2 more hours. Whew again! (and another break)

Now to install the MacPorts python. From Terminal (note that 'sudo' means to surrender total control of everything in my computer to the external site):

sudo port install python27 py27-numpy py27-scipy
sudo port install opencv +python27
sudo port select --set python python27

3 hours later, in Finder select a python source file (.py), in the file info window "open with" entry search for MacPorts' IDLE: it's in /Applications/MacPorts/Python 2.7/ and set it as the app to open python source files. Double-click the python file and watch as nothing happens. Ditto for a double-click on

Another post to the MacPorts forum. I need another module that isn't in the python27 package, and isn't covered in MacPorts' port documentation:

sudo port install py27-tkinter

Two weeks of searching for answers from experts, an age of computer time to follow their advice. But, Python finally works with OpenCV. I got to continue my course.

I passed 'with distinction'. But it sure wasn't thanks to Python. I'm happy being an old fogie, I've returned to ANSI Basic for the things I have to custom program.

John Sankey
other notes on computing