Setting up Python 2.5 on OS X

Posted by Graham Stratton Sun, 13 May 2007 13:47:00 GMT

Sadly, this isn’t quite as simple as it might be. First, set up /usr/local/src/ to contain the source of the packages to be installed:

mkdir /usr/local/src
sudo mkdir /usr/local/src
sudo chgrp admin  /usr/local/src
sudo chmod -R 775 /usr/local/src
cd /usr/local/src

Custom packages are generally installed to /usr/local/, hence /usr/local/src is a sensible place to put the source.

Now install readline:

url -O ftp://ftp.cwru.edu/pub/bash/readline-5.2.tar.gz
tar -xzvf readline-5.2.tar.gz
cd readline-5.2
./configure --prefix=/usr/local
make
sudo make install
cd ..

One of the exciting new batteries included with Python 2.5 is bindings for Sqlite. So, we’d better install that, too:

curl -O http://www.sqlite.org/sqlite-3.3.17.tar.gz
./configure --prefix=/usr/local --with-readline-dir=/usr/local
tar xzvf sqlite-3.3.17.tar.gz 
cd sqlite-3.3.17
./configure --prefix=/usr/local --with-readline-dir=/usr/local
make
sudo make install
cd ..

And finally we can actually build Python:

wget http://www.python.org/ftp/python/2.5.1/Python-2.5.1.tar.bz2
tar xjvf Python-2.5.1.tar.bz2
cd Python-2.5.1/
./configure --prefix=/usr/local --with-readline-dir=/usr/local --with-sqlite3=/usr/local
make
sudo make install
cd ..

Finally, enable tab completion in the interactive interpreter. Set ~/.pythonstartup to contain

import readline, rlcompleter
readline.parse_and_bind("tab: complete")

and set the environment variable PYTHONSTARTUP to point to this file,for example by adding

export PYTHONSTARTUP=~/.pythonstartup

to ~/.bashrc

Phew. Now I can actually do something useful! Maybe my next post will be able to contain some more significant substance!

A quick trick I came across today. I had code working in the interactive interpreter, but I wanted to copy into an editor. So I copied the block into TextMate, and needed to strip out the >>>s, the …s and the output. Text -> Filter Through Command, setting the command to be
egrep ">>>|..." | cut -c5-
and all sorted. Another instance of a nice blend of GUI and command line in OS X.

Posted in ,  | no comments

Comments

(leave url/email »)

   Comment Markup Help Preview comment