This is for installing the psycopg2 PostgreSQL adapter for python.
python –version
in a terminal to be surePython 2.7.1
# change into the psycopg2 directory cd psycopg2-2.5.1 # allow postgres binaries to be available export PATH=$PATH:/usr/local/pgsql/bin # build and install psycopg2 sudo easy_install psycopg2
#!/usr/bin/python import psycopg2 # psycopg features print 'Features of the psycopg are:', print ('API Level: %s, Thread Safety Level: %s, Parameter Style: %s.\n' % \ (psycopg2.apilevel,psycopg2.threadsafety,psycopg2.paramstyle)) # create a connection to the db try: conn=psycopg2.connect("host=localhost dbname=world user=postgres password=mypass") print 'Successfully connected to the database.\n' except: print 'Error: Unable to connect to database!\n' conn.close()