File: install.html

package info (click to toggle)
pygresql 1%3A4.0-3
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 468 kB
  • sloc: ansic: 2,709; python: 1,600; makefile: 63
file content (198 lines) | stat: -rw-r--r-- 11,703 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/" />
<title>PyGreSQL Installation</title>
<link rel="stylesheet" href="docs.css" type="text/css" />
</head>
<body>
<div class="document" id="pygresql-installation">
<h1 class="title">PyGreSQL Installation</h1>
<div class="contents topic">
<p class="topic-title first"><a id="contents" name="contents">Contents</a></p>
<ul class="auto-toc simple">
<li><a class="reference" href="#general" id="id1" name="id1">1&nbsp;&nbsp;&nbsp;General</a></li>
<li><a class="reference" href="#installing-from-a-binary-distribution" id="id2" name="id2">2&nbsp;&nbsp;&nbsp;Installing from a Binary Distribution</a></li>
<li><a class="reference" href="#installing-from-source" id="id3" name="id3">3&nbsp;&nbsp;&nbsp;Installing from Source</a><ul class="auto-toc">
<li><a class="reference" href="#building-and-installing-with-distutils" id="id4" name="id4">3.1&nbsp;&nbsp;&nbsp;Building and installing with Distutils</a></li>
<li><a class="reference" href="#compiling-manually" id="id5" name="id5">3.2&nbsp;&nbsp;&nbsp;Compiling Manually</a></li>
<li><a class="reference" href="#stand-alone" id="id6" name="id6">3.3&nbsp;&nbsp;&nbsp;Stand-Alone</a></li>
<li><a class="reference" href="#built-in-to-python-interpreter" id="id7" name="id7">3.4&nbsp;&nbsp;&nbsp;Built-in to Python interpreter</a></li>
</ul>
</li>
</ul>
</div>
<div class="section">
<h1><a class="toc-backref" href="#id1" id="general" name="general">1&nbsp;&nbsp;&nbsp;General</a></h1>
<p>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
<tt class="docutils literal"><span class="pre">PATH</span></tt> environment variable.</p>
<p>The current version of PyGreSQL has been tested with Python 2.5 and
PostGreSQL 8.3. Older version should work as well, but you will need
at least Python 2.3 and PostgreSQL 7.4.</p>
<p>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.</p>
</div>
<div class="section">
<h1><a class="toc-backref" href="#id2" id="installing-from-a-binary-distribution" name="installing-from-a-binary-distribution">2&nbsp;&nbsp;&nbsp;Installing from a Binary Distribution</a></h1>
<p>This is the easiest way to install PyGreSQL.</p>
<p>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.</p>
<p>Install the package as usual on your system.</p>
<p>Note that the documentation is currently only included in the source package.</p>
</div>
<div class="section">
<h1><a class="toc-backref" href="#id3" id="installing-from-source" name="installing-from-source">3&nbsp;&nbsp;&nbsp;Installing from Source</a></h1>
<p>If you want to install PyGreSQL from Source, or there is no binary
package available for your platform, follow these instructions.</p>
<p>Make sure the Python header files and PostgreSQL client and server header
files are installed. These come usually with the &quot;devel&quot; packages on Unix
systems and the installer executables on Windows systems.</p>
<p>If you are using a precompiled PostgreSQL, you will also need the pg_config
tool. This is usually also part of the &quot;devel&quot; package on Unix, and will be
installed as part of the database server feature on Windows systems.</p>
<div class="section">
<h2><a class="toc-backref" href="#id4" id="building-and-installing-with-distutils" name="building-and-installing-with-distutils">3.1&nbsp;&nbsp;&nbsp;Building and installing with Distutils</a></h2>
<p>You can build and install PyGreSQL using
<a class="reference" href="http://docs.python.org/install/">Distutils</a>.</p>
<p>Download and unpack the PyGreSQL source tarball if you haven't already done so.</p>
<p>Type the following commands to build and install PyGreSQL:</p>
<pre class="literal-block">
python setup.py build
python setup.py install
</pre>
<p>If you are using <a class="reference" href="http://www.mingw.org">MinGW</a> 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 <tt class="docutils literal"><span class="pre">%MinGWpath%/lib/gcc/%MinGWversion%/specs</span></tt> and changing
the entry that reads <tt class="docutils literal"><span class="pre">-lmsvcrt</span></tt> to <tt class="docutils literal"><span class="pre">-lmsvcr71</span></tt>. You may also need to copy
<tt class="docutils literal"><span class="pre">libpq.lib</span></tt> to <tt class="docutils literal"><span class="pre">libpq.a</span></tt> in the PostgreSQL <tt class="docutils literal"><span class="pre">lib</span></tt> directory. Then use
the following command to build and install PyGreSQL:</p>
<pre class="literal-block">
python setup.py build -c mingw32 install
</pre>
<p>Now you should be ready to use PyGreSQL.</p>
</div>
<div class="section">
<h2><a class="toc-backref" href="#id5" id="compiling-manually" name="compiling-manually">3.2&nbsp;&nbsp;&nbsp;Compiling Manually</a></h2>
<p>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.</p>
</div>
<div class="section">
<h2><a class="toc-backref" href="#id6" id="stand-alone" name="stand-alone">3.3&nbsp;&nbsp;&nbsp;Stand-Alone</a></h2>
<ul>
<li><p class="first">In the directory containing <tt class="docutils literal"><span class="pre">pgmodule.c</span></tt>, run the following command:</p>
<pre class="literal-block">
cc -fpic -shared -o _pg.so -I$PYINC -I$PGINC -I$PSINC -L$PGLIB -lpq pgmodule.c
</pre>
<p>where you have to set:</p>
<pre class="literal-block">
PYINC = path to the Python include files
        (usually something like /usr/include/python)
PGINC = path to the PostgreSQL client include files
        (something like /usr/include/pgsql or /usr/include/postgresql)
PSINC = path to the PostgreSQL server include files
        (like /usr/include/pgsql/server or /usr/include/postgresql/server)
PGLIB = path to the PostgreSQL object code libraries (usually /usr/lib)
</pre>
<p>If you are not sure about the above paths, try something like:</p>
<pre class="literal-block">
PYINC=`find /usr -name Python.h`
PGINC=`find /usr -name libpq-fe.h`
PSINC=`find /usr -name postgres.h`
PGLIB=`find /usr -name libpq.so`
</pre>
<p>If you have the <tt class="docutils literal"><span class="pre">pg_config</span></tt> tool installed, you can set:</p>
<pre class="literal-block">
PGINC=`pg_config --includedir`
PSINC=`pg_config --includedir-server`
PGLIB=`pg_config --libdir`
</pre>
<p>Some options may be added to this line:</p>
<pre class="literal-block">
-DNO_DEF_VAR   no default variables support
-DNO_DIRECT    no direct access methods
-DNO_LARGE     no large object support
-DNO_PQSOCKET  if running an older PostgreSQL
</pre>
<p>Define <tt class="docutils literal"><span class="pre">NO_PQSOCKET</span></tt> if you are using a version of PostgreSQL before 6.4
that does not have the PQsocket function. The other options will be
described in the next sections.</p>
<p>On some systems you may need to include <tt class="docutils literal"><span class="pre">-lcrypt</span></tt> in the list of libraries
to make it compile.</p>
</li>
<li><p class="first">Test the new module. Something like the following should work:</p>
<pre class="literal-block">
$ python

&gt;&gt;&gt; import _pg
&gt;&gt;&gt; db = _pg.connect('thilo','localhost')
&gt;&gt;&gt; db.query(&quot;INSERT INTO test VALUES ('ping','pong')&quot;)
18304
&gt;&gt;&gt; db.query(&quot;SELECT * FROM test&quot;)
eins|zwei
----+----
ping|pong
(1 row)
</pre>
</li>
<li><p class="first">Finally, move the <tt class="docutils literal"><span class="pre">_pg.so</span></tt>, <tt class="docutils literal"><span class="pre">pg.py</span></tt>, and <tt class="docutils literal"><span class="pre">pgdb.py</span></tt> to a directory in
your <tt class="docutils literal"><span class="pre">PYTHONPATH</span></tt>. A good place would be <tt class="docutils literal"><span class="pre">/usr/lib/python/site-packages</span></tt>
if your Python modules are in <tt class="docutils literal"><span class="pre">/usr/lib/python</span></tt>.</p>
</li>
</ul>
</div>
<div class="section">
<h2><a class="toc-backref" href="#id7" id="built-in-to-python-interpreter" name="built-in-to-python-interpreter">3.4&nbsp;&nbsp;&nbsp;Built-in to Python interpreter</a></h2>
<ul>
<li><p class="first">Find the directory where your <tt class="docutils literal"><span class="pre">Setup</span></tt> file lives (usually in the <tt class="docutils literal"><span class="pre">Modules</span></tt>
subdirectory) in the Python source hierarchy and copy or symlink the
<tt class="docutils literal"><span class="pre">pgmodule.c</span></tt> file there.</p>
</li>
<li><p class="first">Add the following line to your 'Setup' file:</p>
<pre class="literal-block">
_pg  pgmodule.c -I$PGINC -I$PSINC -L$PGLIB -lpq
</pre>
<p>where:</p>
<pre class="literal-block">
PGINC = path to the PostgreSQL client include files (see above)
PSINC = path to the PostgreSQL server include files (see above)
PGLIB = path to the PostgreSQL object code libraries (see above)
</pre>
<p>Some options may be added to this line:</p>
<pre class="literal-block">
-DNO_DEF_VAR   no default variables support
-DNO_DIRECT    no direct access methods
-DNO_LARGE     no large object support
-DNO_PQSOCKET  if running an older PostgreSQL (see above)
</pre>
<p>On some systems you may need to include <tt class="docutils literal"><span class="pre">-lcrypt</span></tt> in the list of libraries
to make it compile.</p>
</li>
<li><p class="first">If you want a shared module, make sure that the <tt class="docutils literal"><span class="pre">shared</span></tt> keyword is
uncommented and add the above line below it. You used to need to install
your shared modules with <tt class="docutils literal"><span class="pre">make</span> <span class="pre">sharedinstall</span></tt> but this no longer seems
to be true.</p>
</li>
<li><p class="first">Copy <tt class="docutils literal"><span class="pre">pg.py</span></tt> to the lib directory where the rest of your modules are.
For example, that's <tt class="docutils literal"><span class="pre">/usr/local/lib/Python</span></tt> on my system.</p>
</li>
<li><p class="first">Rebuild Python from the root directory of the Python source hierarchy by
running <tt class="docutils literal"><span class="pre">make</span> <span class="pre">-f</span> <span class="pre">Makefile.pre.in</span> <span class="pre">boot</span></tt> and <tt class="docutils literal"><span class="pre">make</span> <span class="pre">&amp;&amp;</span> <span class="pre">make</span> <span class="pre">install</span></tt>.</p>
</li>
<li><p class="first">For more details read the documentation at the top of <tt class="docutils literal"><span class="pre">Makefile.pre.in</span></tt>.</p>
</li>
</ul>
</div>
</div>
</div>
</body>
</html>