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.

3 Comments:

Anonymous Andy Todd said...

It probably doesn't make a lot of difference, but I would replace the last step with a .pth file pointing to your checked out version of the Django code.

And if you want a more up to date version of MySQL you can always try Macports - http://www.macports.org

12:56 AM  
Blogger galloglass said...

[Pause while I look up .pth files; despite any minimal evidence to the contrary, I'm not really a Pythonista yet]

Ah yes, that would probably be a better mechanism to use in general—it looks portable to those sad operating systems that don't have symlinks :-)

Thanks for the tip.

9:10 AM  
Anonymous Anonymous said...

thx for help.

I`d like to play with mysql and python.

http://wiki.mobbing-gegner.de/Python/Module/mysqldb

Hope to find the fix :)

10:54 AM  

Post a Comment

<< Home