Python 2.6, Leopard 10.5.6 and psycopg 2.0.10

Psycopg2 is the postgreSQL adapter for Django. If you are trying to set it up on Mac OSX (using the supplied setup.py script) you may run into an error saying

File "setup.py", line 219, in finalize_options
NameError: global name 'w' is not defined

This is a simple thing to fix: open the setup.py file coming with psycopg2 and edit the line 219 like this:

except (Warning, w):

Remove the braces

except Warning, w:

In python 2.6 (at least) putting exceptions in brackets will catch multiple exceptions in this case Warnings and 'w's. The author clearly meant to get the Warning instance as 'w'. Also, do not forget to edit the setup.cfg file on line 28 and type in your pg_config path. Mine is

pg_config=/Library/PostgreSQL/8.3/bin/pg_config

and so should yours be if you used the default installer package for mac OS X. Oh, yeah, you need to install postgres before installing psycopg2.

One Comment

  1. Jonathan says:

    Thanks!

    2.0.11 wouldn't work on osx 10.5.7 (python 2.5) and 2.0.10 was giving this error.

    This works like a charm.

Leave a Reply