Today: August 27th, 2008

How To Install PyGreSQL in Windows

To give myself a reference the next time I reinstall PyGreSQL. The steps below was taken verbatim from PyGreSQL mailing list http://mailman.vex.net/mailman/listinfo/pygresql. This was provided by Christoph Zwerschke.

I was hacking my PyGreSQL install before by putting the PostgreSQL dlls in the WINDOWS directory. I’m glad there’s a better and easier way to do it.

===========================================
HOW TO INSTALL PYGRESQL ON WIN WITH DISTUTILS AND MINGW
===========================================

Windows XP SP2
Python: 2.4.2
PostgreSQL 8.1.2
MinGW 5.0
PyGreSQL 3.8

*** Required resources ***

(1) Python 2.4.2 binaries for Windows,
www.python.org/ftp/python/2.4.2/python-2.4.2.msi
(2) PostgreSQL 8.1.2 binaries for Windows,
www.postgresql.org/ftp/binary/v8.1.2/win32/
(3) Current MinGW (Windows exe installer),
prdownloads.sf.net/mingw/MinGW-5.0.0.exe
(4) PyGreSQL 3.8 source,
ftp.pygresql.org/pub/distrib/PyGreSQL-3.8.tgz

*** Installation ***

* Install Python (1)
Run the python-2.4.2.msi installer.

* Install PostgreSQL (2)
Run the postgresql-8.1.msi installer.
The “Database Server” feature must be selected.
Add “Include files” and “Library files” (but not the
MS VC++ library files) from the “Development” feature
when asked for the installation options. All other
features are not necessary for building PyGreSQL.
Actually, you don’t even need to install the server.
What is needed is only the pg_config executable which
happens to be part of the server feature.

* Install MinGW (3)
Run the MinGW-5.0.0.exe installer.
Choose a mirror site, download and install current package.
It is sufficient to install the “MinGW base tools”.
Edit the file “%MinGWpath%\lib\gcc\%MinGWversion%\specs”
and change the entry that reads -lmsvcrt to -lmsvcr71.
(MinGW uses msvcrt as its common runtime library as opposed
to the official Python distribution which uses the msvcr71).

* Extract pygresql-3.8.tgz (4)
somewhere and open a Windows cmd shell in that directory.
Type the following command:

python setup.py build -c mingw32 install

This should run through without errors and install PyGreSQL.

You can also create a Windows installer as simply as:

python setup.py build -c mingw32 bdist_wininst

Note that the path to the libpq.dll is not hard coded into
PyGreSQL (so it will be redistributable). That means you have
to copy the installed libpq.dll to a place where it will be
found by the system, or include it to the Windows PATH.

*** Testing ***

* Start the PostgreSQL server.
* Enter the following statements in Python:

from pg import DB
db = DB(’template1′, user=’postgres’, passwd=’your_passwd’)
q = db.query(”select (1+1)*3*7 as the_answer”)
print q.dictresult()[0]
# this should print {’the_answer’: 42}
print str(q)
# this should print ”
print q
# this should print:
the_answer
———-
42
(1 row)

_______________________________________________
PyGreSQL mailing list
PyGreSQL@Vex.Net
http://mailman.vex.net/mailman/listinfo/pygresql

comments

Leave a Reply