<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Straight Ornamental: Category Mac</title>
    <link>http://grahamstratton.org/blog/public/articles/category/mac</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Ramblings from a rambler</description>
    <item>
      <title>Setting up Python 2.5 on OS X</title>
      <description>&lt;p&gt;Sadly, this isn&amp;#8217;t quite as simple as it might be.  First, set up /usr/local/src/ to contain the source of the packages to be installed:&lt;/p&gt;


&lt;pre&gt;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&lt;/pre&gt;

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


	&lt;p&gt;Now install readline:&lt;/p&gt;


&lt;pre&gt;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 ..&lt;/pre&gt;

	&lt;p&gt;One of the exciting new batteries included with Python 2.5 is bindings for Sqlite.  So, we&amp;#8217;d better install that, too:&lt;/p&gt;


&lt;pre&gt;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 ..&lt;/pre&gt;

	&lt;p&gt;And finally we can actually build Python:&lt;/p&gt;


&lt;pre&gt;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 ..&lt;/pre&gt;

	&lt;p&gt;Finally, enable tab completion in the interactive interpreter.  Set ~/.pythonstartup to contain&lt;/p&gt;


&lt;pre&gt;import readline, rlcompleter
readline.parse_and_bind("tab: complete")&lt;/pre&gt;

	&lt;p&gt;and set the environment variable &lt;span class="caps"&gt;PYTHONSTARTUP&lt;/span&gt; to point to this file,for example by adding&lt;/p&gt;


&lt;pre&gt;export PYTHONSTARTUP=~/.pythonstartup&lt;/pre&gt;

	&lt;p&gt;to ~/.bashrc&lt;/p&gt;


	&lt;p&gt;Phew. Now I can actually do something useful! Maybe my next post will be able to contain some more significant substance!&lt;/p&gt;


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 &amp;gt;&amp;gt;&amp;gt;s, the &amp;#8230;s and the output.  Text -&amp;gt; Filter Through Command, setting the command to be 
&lt;pre&gt;egrep "&amp;gt;&amp;gt;&amp;gt;|..." | cut -c5-&lt;/pre&gt; and all sorted. Another instance of a nice blend of &lt;span class="caps"&gt;GUI&lt;/span&gt; and command line in &lt;span class="caps"&gt;OS X&lt;/span&gt;.</description>
      <pubDate>Sun, 13 May 2007 13:47:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:a5dfaee2-c58b-4494-aee9-0946ac31c70f</guid>
      <author>Graham Stratton</author>
      <link>http://grahamstratton.org/blog/public/articles/2007/05/13/setting-up-python-2-5-on-os-x</link>
      <category>Python</category>
      <category>Mac</category>
    </item>
    <item>
      <title>Generating Pie Charts with Python under OS X</title>
      <description>&lt;p&gt;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.&lt;/p&gt;


	&lt;p&gt;Well, it&amp;#8217;s taken me most of a day, and I haven&amp;#8217;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&amp;#8217;d go the whole way and install matplotlib, which builds on scipy.&lt;/p&gt;


	&lt;p&gt;I thought I&amp;#8217;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 &lt;span class="caps"&gt;GNU F77&lt;/span&gt; compiler.&lt;/p&gt;


	&lt;p&gt;Numpy installed fine, but scipy required fftw (which also had to be compiled from source, and some other things.&lt;/p&gt;


	&lt;p&gt;Compilation then stalled with:&lt;/p&gt;


	&lt;p&gt;/usr/bin/ld: can&amp;#8217;t locate file for: -ldfftpack&lt;/p&gt;


	&lt;p&gt;which was solved by running&lt;/p&gt;


	&lt;p&gt;python setup.py build_clib&lt;/p&gt;


	&lt;p&gt;which creates libdfftpack.a, before continuing before the standard build.  Poor dependency handling between numpy.distutils commands is apparently to blame.&lt;/p&gt;


	&lt;p&gt;Then I ran the scipy tests and some of them failed.  There&amp;#8217;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.&lt;/p&gt;


	&lt;p&gt;I moved on to attempting to install matplotlib.  I found a suitable egg, and tried to easy_install it.  A linking error for libpng.&lt;/p&gt;


	&lt;p&gt;sudo port install libpng&lt;/p&gt;


	&lt;p&gt;didn&amp;#8217;t produce an error, but didn&amp;#8217;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&amp;#8217;t enough.  So I depaired, and returned to Google.&lt;/p&gt;


	&lt;p&gt;I found some pre-built packages for &lt;span class="caps"&gt;OS X&lt;/span&gt;, but they used the system python 2.4, where I was happy with my compiled version, and didn&amp;#8217;t want a new one, and figured that installing a new system python would confuse things.&lt;/p&gt;


	&lt;p&gt;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&lt;/p&gt;


	&lt;p&gt;import pylab&lt;/p&gt;


	&lt;p&gt;yielded&lt;/p&gt;


	&lt;p&gt;ImportError: No module named wx&lt;/p&gt;


	&lt;p&gt;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.&lt;/p&gt;


	&lt;p&gt;The new system python is at /usr/bin/python  &amp;#8211; but none of the tons of stuff I had already installed is available.  So I&amp;#8217;m not sure that I&amp;#8217;ve gained anything.  Especially since&lt;/p&gt;


	&lt;p&gt;import pylab&lt;/p&gt;


	&lt;p&gt;now yields&lt;/p&gt;


	&lt;p&gt;ImportError: No module named numpy&lt;/p&gt;


	&lt;p&gt;and fixing that returns me to&lt;/p&gt;


	&lt;p&gt;No module named wx&lt;/p&gt;


	&lt;p&gt;Installing the wx binaries left me with a working import.  Inspired by this, I installed the darwinports binaries with&lt;/p&gt;


	&lt;p&gt;sudo port install py-wxpython&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;m hoping this will solve my problems!&lt;/p&gt;


	&lt;p&gt;But no.  Now I&amp;#8217;ve even got two terminals which report the same path for &amp;#8216;which python&amp;#8217;, but actually start different versions of the interpreter.&lt;/p&gt;


	&lt;p&gt;In summary, it&amp;#8217;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&amp;#8217;m going to have to install this on a debian system too at some point.  I&amp;#8217;m anticipating it being rather more trivial.&lt;/p&gt;</description>
      <pubDate>Wed, 22 Nov 2006 21:54:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:08936a9b-f48b-4317-b46e-7a0d48fbbe04</guid>
      <author>Graham Stratton</author>
      <link>http://grahamstratton.org/blog/public/articles/2006/11/22/generating-pie-charts-with-python-under-os-x</link>
      <category>Python</category>
      <category>Mac</category>
    </item>
    <item>
      <title>Postgres on OS X</title>
      <description>&lt;p&gt;Today I needed to install postgres on &lt;span class="caps"&gt;OS X&lt;/span&gt;, and it was sadly rather complex.  Therefore, here&amp;#8217;s a quick guide for myself in future.&lt;/p&gt;


I chose Darwin ports to install Postgres:
&lt;pre&gt;
sudo port sync
sudo port install postgresql8 +server
&lt;/pre&gt;
the +server command creates a postgres8 user.

Then I needed to update my bash profile:
&lt;pre&gt;
sudo -s
echo "PATH=$PATH:/opt/local/lib/postgresql81/bin" &amp;gt;&amp;gt; /etc/profile
echo "export PATH" &amp;gt;&amp;gt; /etc/profile
echo "export PGDATA=/usr/local/pgsql/data" &amp;gt;&amp;gt; /etc/profile
exit
source /etc/profile
&lt;/pre&gt;

create the data directory and start Postgres:
&lt;pre&gt;
sudo mkdir -p /usr/local/pgsql
sudo chown postgres8 /usr/local/pgsql/
sudo -u postgres8 initdb
sudo -u postgres8 pg_ctl start
&lt;/pre&gt;

then finally databsaes can be created:
&lt;pre&gt;
sudo -u postgres8 createdb tutors
&lt;/pre&gt;</description>
      <pubDate>Tue, 22 Aug 2006 13:24:40 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:e1ff7219-ac5c-45f4-8507-674ac07735d3</guid>
      <author>Graham Stratton</author>
      <link>http://grahamstratton.org/blog/public/articles/2006/08/22/postgres-on-os-x</link>
      <category>Mac</category>
    </item>
  </channel>
</rss>
