Friday, November 17, 2006

Django

Today, my installation notes on the steps I took to get Django set up and running (Mac OS X version still at 10.3.9).

The general picture of the chunks of software involved is:

django

At first glance, my machine has Python and MySQL already installed:

   ~:which python
   /usr/bin/python
   ~:which mysql
   /usr/local/mysql/bin/mysql
 

so it looks like it should just be a case of adding in MySQLdb and Django itself.

MySQLdb

First, I downloaded and unpacked MySQL-python-1.2.1_p2.tar.gz from this page. However, reading the README file, it looks like there are some version dependencies:

  • MySQL >= 3.23.32: A quick run of status from inside mysql shows my version as 4.1.15, so that's OK.
  • Python >= 2.3.3: running /usr/bin/python -V just shows "Python 2.3". Thanks to this page, I could run import platform;print platform.python_version() in the Python interpreter and discovered that the built-in version of Python is 2.3.0. Drat.

PUSH: Python 2.5

Quick digression to visit the Mac Python page and download a copy of Python 2.5. A normal Mac install procedure means that I've now got a /usr/local/bin/python that reports 2.5.0, and it appears to be installed under /Library/Frameworks/Python.framework/Versions/2.5

POP: Back to MySQLdb

In the MySQL-python-1.2.1_p2 directory, I did a quick chmod +x setup.py and then ran setup.py build. This built very quickly, producing some stuff in the build/ subdirectory. Running sudo setup.py install put things into the /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages directory.

Time for a quick test to check that everything is OK, using a Bugzilla database I've got running locally:

~:python
Python 2.5 (r25:51918, Sep 19 2006, 08:49:13) 
[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import _mysql
>>> db=_mysql.connect(host="localhost", user="bugs", passwd="password", db="bugs")
>>> db.query("""select short_desc from bugs where bug_id < 10""")
>>> r=db.store_result()
>>> r.fetch_row()
(('tracker.exe fails to run',),)
>>> r.fetch_row(10)
(('Using Word as email editor confuses tracker',), 
 ('Mysteriously, many items have people = "none" should just be blank',), 
 ('keyword combo should have whole description in it, not "same description"',), 
 ('Dodgy start/end times just get mysteriously dropped',), 
 ('Detect and drop the addition of duplicate keywords',), 
 ("Get rid of menus that we don't use",), 
 ('Add wildcards to project keywords',), 
 ('Add help to activity forms',))
>>> 

Looks good.

[Edit 2008-07-20: When I repeated this process later (on 10.5), I also needed to follow these instructions.]

Django

I decided to take the Django folks at their word when they claim that the development version is pretty stable, so I checked out the code with svn co http://code.djangoproject.com/svn/django/trunk/ as suggested. (I downloaded in November 2006, at which point the highest stable release was 0.95).

To make Django visible within Python just needed a sudo ln -s `pwd`/trunk/django/ /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django. (To check it was visible, a quick import django in Python didn't generate any errors.)

From here on, the normal Django documentation can take over.

Thursday, November 09, 2006

Round Three: Return to Plan A

Plan A has been successfully resurrected and completed, with a mere 6 day pause for step 3. I found a much more helpful set of folk, so it was just a case of killing time in town while steps 1 and 4 took place.