Welcome, Guest! Registration


Thursday, 2018-03-22
Main » 2012 » March » 25 » PostgreSQL with Python at Amazon Elastic Cloud
1:58 AM
PostgreSQL with Python at Amazon Elastic Cloud

I have Python 2.6.7 and PostgreSQL 8.4.9 on my ec2 machine - all "stock". When it came to interacting between those two, I opted for psycopg2 Python module, which implements Python DB API 2.0 specifications. The module seems to be quite mainstream, timely updated, and compliance with standards is a positive thing in my eyes. :-)

My current PostgreSQL install has

[ec2-user@ip ~]$ rpm -qa | grep postgres
In order to get the programmatic access, we need to get libpq-dev. Couldnot think of anything but libpq from postgresql-devel:
[ec2-user@ip ~]$ sudo yum install postgresql-devel

The other pre-requisite - python-dev, seemed to be there already (I might have installed it before):

[ec2-user@ip ~]$ rpm -qa | grep python-dev

The last requirement is to have pg_config in the PATH.

[ec2-user@ip ]$ which pg_config
confirmed - it is.

I installed from source as they claim easy_install would not resolve these dependencies anyway; but I am pretty confident that sudo easy_install psycopg2 would have worked just fine.

To install from the source, I downloaded the archive from the Download page. It happened to be the source package for psycopg2-2.4.4 - http://initd.org/psycopg/tarballs/PSYCOPG-2-4/psycopg2-2.4.4.tar.gz.

Then it was easy:

[ec2-user@ip ]$ tar -zxf psycopg2-2.4.4.tar.gz
[ec2-user@ip ]$ cd psycopg2-2.4.4
[ec2-user@ip ]$ sudo python setup.py install

The install command ended up with Writing /usr/lib64/python2.6/site-packages/psycopg2-2.4.4-py2.6.egg-info, and I could not spot errors, so I assume psycopg2-2.4.4 is installed just fine.

Let's give it a smoke test:

[ec2-user@ip-10-64-54-250 psycopg2-2.4.4]$ python
Python 2.6.7 (r267:88850, Jun 4 2011, 04:34:02)
[GCC 4.4.4 20100726 (Red Hat 4.4.4-13)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
Well, so far so good (at least it imports).

Additional info
  1. psycopg officiall web site - http://initd.org/psycopg/
  2. psycopg PyPi - http://pypi.python.org/pypi/psycopg2
Views: 3252 | Added by: loc2logg | Tags: Database, Linux, install, amazon ec2, Python, postgresql, dbi, psycopg2 | Rating: 0.0/0
Total comments: 0
Only registered users can add comments.
[ Registration | Login ]