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 Python, Mac | 243 comments
Posted by Graham Stratton
Wed, 22 Nov 2006 21:54:00 GMT
It sounded like a trivial task: find a library which will produce pie charts for use on the web which has a python interface. Then install it and use it.
Well, it’s taken me most of a day, and I haven’t got there yet. There are a number of small tools which might do the job, but none of them looked quite right, so I thought I’d go the whole way and install matplotlib, which builds on scipy.
I thought I’d see whether these packages were available from the cheese shop. I think they all are, but the install of scipy failed. The first problem was that scientific stuff is written in fortran, so I had to install (from source, no darwinport) gfortran, the GNU F77 compiler.
Numpy installed fine, but scipy required fftw (which also had to be compiled from source, and some other things.
Compilation then stalled with:
/usr/bin/ld: can’t locate file for: -ldfftpack
which was solved by running
python setup.py build_clib
which creates libdfftpack.a, before continuing before the standard build. Poor dependency handling between numpy.distutils commands is apparently to blame.
Then I ran the scipy tests and some of them failed. There’s a point where it says it would use the Atlas libraries if they were available. I spent a while trying to get them to install, but failed.
I moved on to attempting to install matplotlib. I found a suitable egg, and tried to easy_install it. A linking error for libpng.
sudo port install libpng
didn’t produce an error, but didn’t fix things. Compiling from source manually did. Then I got errors about not being able to find libfreetype. I though a sym-link to the library deep in /Developer/SDKs/MacOSX10.4u.sdk/ would do the trick, but it wasn’t enough. So I depaired, and returned to Google.
I found some pre-built packages for OS X, but they used the system python 2.4, where I was happy with my compiled version, and didn’t want a new one, and figured that installing a new system python would confuse things.
Darwinports also contained a port of matplotlib, so I thought that I would try that. That also insisted on installing its own python, but I was despairing, so I tried it. The full install succeeded, but
import pylab
yielded
ImportError: No module named wx
For some reason I concluded that this was more than the simple dependency problem it appears to be, and decided to try to pre-built packages instead. They installed successfully, I just need to work out how to run the python interpreter I want.
The new system python is at /usr/bin/python – but none of the tons of stuff I had already installed is available. So I’m not sure that I’ve gained anything. Especially since
import pylab
now yields
ImportError: No module named numpy
and fixing that returns me to
No module named wx
Installing the wx binaries left me with a working import. Inspired by this, I installed the darwinports binaries with
sudo port install py-wxpython
I’m hoping this will solve my problems!
But no. Now I’ve even got two terminals which report the same path for ‘which python’, but actually start different versions of the interpreter.
In summary, it’s all a mess, and I ought to learn a bit more about how compiled languages work (in particular, how the linker looks for libraries). I’m going to have to install this on a debian system too at some point. I’m anticipating it being rather more trivial.
Posted in Python, Mac | 33 comments
Posted by Graham Stratton
Tue, 22 Aug 2006 13:24:40 GMT
Today I needed to install postgres on OS X, and it was sadly rather complex. Therefore, here’s a quick guide for myself in future.
I chose Darwin ports to install Postgres:
sudo port sync
sudo port install postgresql8 +server
the +server command creates a postgres8 user.
Then I needed to update my bash profile:
sudo -s
echo "PATH=$PATH:/opt/local/lib/postgresql81/bin" >> /etc/profile
echo "export PATH" >> /etc/profile
echo "export PGDATA=/usr/local/pgsql/data" >> /etc/profile
exit
source /etc/profile
create the data directory and start Postgres:
sudo mkdir -p /usr/local/pgsql
sudo chown postgres8 /usr/local/pgsql/
sudo -u postgres8 initdb
sudo -u postgres8 pg_ctl start
then finally databsaes can be created:
sudo -u postgres8 createdb tutors
Posted in Mac | 2 comments