After running http://web2py.googlecode.com/hg/scripts/setup-web2py-ubuntu.sh on ubuntu 10.10 and setting up a postgres db for an app, I was getting "global name 'psycopg2' is not defined". Fixed it with:
apt-get install python-psycopg2
sudo /etc/init.d/apache2 restart
For 10.10, the line
apt-get -y install python2.5-psycopg2
...should read:
apt-get -y install python-psycopg2

