Installation

General

You must first have installed Python and PostgreSQL on your system. If you want to access remote database only, you don't need to install the full PostgreSQL server, but only the C interface (libpq). If you are on Windows, make sure that the directory with libpq.dll is in your PATH environment variable.

The current version of PyGreSQL has been tested with Python versions 2.6, 2.7, 3.3, 3.4, 3.5 and PostGreSQL version 9.0 to 9.4.

PyGreSQL will be installed as three modules, a dynamic module called _pg.pyd, and two pure Python wrapper modules called pg.py and pgdb.py. All three files will be installed directly into the Python site-packages directory. To uninstall PyGreSQL, simply remove these three files again.

Installing from a Binary Distribution

This is the easiest way to install PyGreSQL.

You can currently download PyGreSQL as Linux RPM, NetBSD package and Windows installer. Make sure the required Python version of the binary package matches the Python version you have installed.

Install the package as usual on your system.

Note that the documentation is currently only included in the source package.

Installing from Source

If you want to install PyGreSQL from Source, or there is no binary package available for your platform, follow these instructions.

Make sure the Python header files and PostgreSQL client and server header files are installed. These come usually with the "devel" packages on Unix systems and the installer executables on Windows systems.

If you are using a precompiled PostgreSQL, you will also need the pg_config tool. This is usually also part of the "devel" package on Unix, and will be installed as part of the database server feature on Windows systems.

Building and installing with Distutils

You can build and install PyGreSQL using Distutils.

Download and unpack the PyGreSQL source tarball if you haven't already done so.

Type the following commands to build and install PyGreSQL:

python setup.py build
python setup.py install

If you are using MinGW to build PyGreSQL under Microsoft Windows, please note that Python newer version 2.3 is using msvcr71 instead of msvcrt as its common runtime library. You can allow for that by editing the file %MinGWpath%/lib/gcc/%MinGWversion%/specs and changing the entry that reads -lmsvcrt to -lmsvcr71. You may also need to copy libpq.lib to libpq.a in the PostgreSQL lib directory. Then use the following command to build and install PyGreSQL:

python setup.py build -c mingw32 install

Now you should be ready to use PyGreSQL.

Compiling Manually

The source file for compiling the dynamic module is called pgmodule.c. You have two options. You can compile PyGreSQL as a stand-alone module or you can build it into the Python interpreter.

Stand-Alone

Built-in to Python interpreter