PostgreSQL

Installing Psycopg2

javamix 2013. 1. 4. 10:12

python psycopg2

========================================================================================

Installing Psycopg2   

========================================================================================

wget http://www.initd.org/psycopg/tarballs/psycopg2-latest.tar.gz

tar xvfz psycopg2-latest.tar.gz

mv psycopg2-2.4.6 /usr/local/src

cd psycopg2-2.4.6/

python setup.py install



[root@kkk psycopg2-2.4.6]# python

Python 2.4.3 (#1, Feb 22 2012, 16:06:13)

[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> import psycopg2

>>>


No message means that it has successfully loaded!


Python 실행 파일 위치 및 버젼 알기


[root@kkk examples]# which python

/usr/bin/python

[root@kkk examples]# python -V

Python 2.4.3



[root@kkk examples]# cat helloworld.py

#!/usr/bin/python

import psycopg2

import sys


def main():

        #Define our connection string

        conn_string = "host='192.168.9.131' dbname='edb' port='5448' user='enterprisedb' password='pw'"


        # print the connection string we will use to connect

        print "Connecting to database\n ->%s" % (conn_string)


        # get a connection, if a connect cannot be made an exception will be raised here

        conn = psycopg2.connect(conn_string)


        # conn.cursor will return a cursor object, you can use this cursor to perform queries

        cursor = conn.cursor()

        print "Connected!\n"


if __name__ == "__main__":

        main()



[root@kkk examples]# python helloworld.py

Connecting to database

        ->host='192.168.9.131' dbname='edb' port='5448' user='enterprisedb' password='pw'

Connected!



참조 : (http://www.webtop.com.au/blog/installing-postgresql-and-psycopg2-2009030344)