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 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
|
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Installation — PyGreSQL 5.0 documentation</title>
<link rel="stylesheet" href="../_static/cloud.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygresql.css" type="text/css" />
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Noticia+Text|Open+Sans|Droid+Sans+Mono" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '5.0.3',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<script type="text/javascript" src="../_static/jquery.cookie.js"></script>
<script type="text/javascript" src="../_static/cloud.js"></script>
<link rel="shortcut icon" href="../_static/favicon.ico"/>
<link rel="copyright" title="Copyright" href="../copyright.html" />
<link rel="top" title="PyGreSQL 5.0 documentation" href="index.html" />
<link rel="next" title="ChangeLog" href="changelog.html" />
<link rel="prev" title="The PyGreSQL documentation" href="index.html" />
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body role="document">
<div class="pageheader related" role="navigation" aria-label="related navigation">
<ul>
<li><a href="../index.html">Home</a></li>
<li><a href="../download/index.html">Download</a></li>
<li><a href="index.html">Documentation</a></li>
<li><a href="../community/index.html">Community</a></li>
</ul>
<div class="logo">
<a href="../index.html">PyGreSQL</a>
</div>
</div>
</div>
<div class="relbar-top">
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> </li>
<li class="right" >
<a href="changelog.html" title="ChangeLog"
accesskey="N">next</a> </li>
<li class="right" >
<a href="index.html" title="The PyGreSQL documentation"
accesskey="P">previous</a> </li>
<li><a href="index.html">PyGreSQL 5.0 documentation</a> »</li>
</ul>
</div>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="installation">
<h1>Installation<a class="headerlink" href="#installation" title="Permalink to this headline">¶</a></h1>
<div class="section" id="general">
<h2>General<a class="headerlink" href="#general" title="Permalink to this headline">¶</a></h2>
<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
<code class="docutils literal"><span class="pre">PATH</span></code> environment variable.</p>
<p>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.5.</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" id="installing-with-pip">
<h2>Installing with Pip<a class="headerlink" href="#installing-with-pip" title="Permalink to this headline">¶</a></h2>
<p>This is the most easy way to install PyGreSQL if you have “pip” installed
on your computer. Just run the following command in your terminal:</p>
<div class="highlight-default"><div class="highlight"><pre><span class="n">pip</span> <span class="n">install</span> <span class="n">PyGreSQL</span>
</pre></div>
</div>
<p>This will automatically try to find and download a distribution on the
<a class="reference external" href="https://pypi.python.org/">Python Package Index</a> that matches your operating
system and Python version and install it on your computer.</p>
</div>
<div class="section" id="installing-from-a-binary-distribution">
<h2>Installing from a Binary Distribution<a class="headerlink" href="#installing-from-a-binary-distribution" title="Permalink to this headline">¶</a></h2>
<p>If you don’t want to use “pip”, or “pip” doesn’t find an appropriate
distribution for your computer, you can also try to manually download
and install a distribution.</p>
<p>When you download the source distribution, you will need to compile the
C extensions, for which you need a C compiler installed on your computer.
If you don’t want to install a C compiler or avoid possible problems
with the compilation, you can search for a pre-compiled binary distribution
of PyGreSQL on the Python Package Index or the PyGreSQL homepage.</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" id="installing-from-source">
<h2>Installing from Source<a class="headerlink" href="#installing-from-source" title="Permalink to this headline">¶</a></h2>
<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 “devel” 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 “devel” package on Unix, and will be
installed as part of the database server feature on Windows systems.</p>
<div class="section" id="building-and-installing-with-distutils">
<h3>Building and installing with Distutils<a class="headerlink" href="#building-and-installing-with-distutils" title="Permalink to this headline">¶</a></h3>
<p>You can build and install PyGreSQL using
<a class="reference external" 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>
<div class="highlight-default"><div class="highlight"><pre><span class="n">python</span> <span class="n">setup</span><span class="o">.</span><span class="n">py</span> <span class="n">build</span>
<span class="n">python</span> <span class="n">setup</span><span class="o">.</span><span class="n">py</span> <span class="n">install</span>
</pre></div>
</div>
<p>Now you should be ready to use PyGreSQL.</p>
</div>
<div class="section" id="compiling-manually">
<h3>Compiling Manually<a class="headerlink" href="#compiling-manually" title="Permalink to this headline">¶</a></h3>
<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 class="section" id="stand-alone">
<h4>Stand-Alone<a class="headerlink" href="#stand-alone" title="Permalink to this headline">¶</a></h4>
<ul>
<li><p class="first">In the directory containing <code class="docutils literal"><span class="pre">pgmodule.c</span></code>, run the following command:</p>
<div class="highlight-default"><div class="highlight"><pre>cc -fpic -shared -o _pg.so -I$PYINC -I$PGINC -I$PSINC -L$PGLIB -lpq pgmodule.c
</pre></div>
</div>
<p>where you have to set:</p>
<div class="highlight-default"><div class="highlight"><pre><span class="n">PYINC</span> <span class="o">=</span> <span class="n">path</span> <span class="n">to</span> <span class="n">the</span> <span class="n">Python</span> <span class="n">include</span> <span class="n">files</span>
<span class="p">(</span><span class="n">usually</span> <span class="n">something</span> <span class="n">like</span> <span class="o">/</span><span class="n">usr</span><span class="o">/</span><span class="n">include</span><span class="o">/</span><span class="n">python</span><span class="p">)</span>
<span class="n">PGINC</span> <span class="o">=</span> <span class="n">path</span> <span class="n">to</span> <span class="n">the</span> <span class="n">PostgreSQL</span> <span class="n">client</span> <span class="n">include</span> <span class="n">files</span>
<span class="p">(</span><span class="n">something</span> <span class="n">like</span> <span class="o">/</span><span class="n">usr</span><span class="o">/</span><span class="n">include</span><span class="o">/</span><span class="n">pgsql</span> <span class="ow">or</span> <span class="o">/</span><span class="n">usr</span><span class="o">/</span><span class="n">include</span><span class="o">/</span><span class="n">postgresql</span><span class="p">)</span>
<span class="n">PSINC</span> <span class="o">=</span> <span class="n">path</span> <span class="n">to</span> <span class="n">the</span> <span class="n">PostgreSQL</span> <span class="n">server</span> <span class="n">include</span> <span class="n">files</span>
<span class="p">(</span><span class="n">like</span> <span class="o">/</span><span class="n">usr</span><span class="o">/</span><span class="n">include</span><span class="o">/</span><span class="n">pgsql</span><span class="o">/</span><span class="n">server</span> <span class="ow">or</span> <span class="o">/</span><span class="n">usr</span><span class="o">/</span><span class="n">include</span><span class="o">/</span><span class="n">postgresql</span><span class="o">/</span><span class="n">server</span><span class="p">)</span>
<span class="n">PGLIB</span> <span class="o">=</span> <span class="n">path</span> <span class="n">to</span> <span class="n">the</span> <span class="n">PostgreSQL</span> <span class="nb">object</span> <span class="n">code</span> <span class="n">libraries</span> <span class="p">(</span><span class="n">usually</span> <span class="o">/</span><span class="n">usr</span><span class="o">/</span><span class="n">lib</span><span class="p">)</span>
</pre></div>
</div>
<p>If you are not sure about the above paths, try something like:</p>
<div class="highlight-default"><div class="highlight"><pre>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></div>
</div>
<p>If you have the <code class="docutils literal"><span class="pre">pg_config</span></code> tool installed, you can set:</p>
<div class="highlight-default"><div class="highlight"><pre>PGINC=`pg_config --includedir`
PSINC=`pg_config --includedir-server`
PGLIB=`pg_config --libdir`
</pre></div>
</div>
<p>Some options may be added to this line:</p>
<div class="highlight-default"><div class="highlight"><pre><span class="o">-</span><span class="n">DNO_DEF_VAR</span> <span class="n">no</span> <span class="n">default</span> <span class="n">variables</span> <span class="n">support</span>
<span class="o">-</span><span class="n">DNO_DIRECT</span> <span class="n">no</span> <span class="n">direct</span> <span class="n">access</span> <span class="n">methods</span>
<span class="o">-</span><span class="n">DNO_LARGE</span> <span class="n">no</span> <span class="n">large</span> <span class="nb">object</span> <span class="n">support</span>
<span class="o">-</span><span class="n">DNO_PQSOCKET</span> <span class="k">if</span> <span class="n">running</span> <span class="n">an</span> <span class="n">older</span> <span class="n">PostgreSQL</span>
</pre></div>
</div>
<p>On some systems you may need to include <code class="docutils literal"><span class="pre">-lcrypt</span></code> 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>
<div class="highlight-default"><div class="highlight"><pre>$ python
>>> import _pg
>>> db = _pg.connect('thilo','localhost')
>>> db.query("INSERT INTO test VALUES ('ping','pong')")
18304
>>> db.query("SELECT * FROM test")
eins|zwei
----+----
ping|pong
(1 row)
</pre></div>
</div>
</li>
<li><p class="first">Finally, move the <code class="docutils literal"><span class="pre">_pg.so</span></code>, <code class="docutils literal"><span class="pre">pg.py</span></code>, and <code class="docutils literal"><span class="pre">pgdb.py</span></code> to a directory in
your <code class="docutils literal"><span class="pre">PYTHONPATH</span></code>. A good place would be <code class="docutils literal"><span class="pre">/usr/lib/python/site-packages</span></code>
if your Python modules are in <code class="docutils literal"><span class="pre">/usr/lib/python</span></code>.</p>
</li>
</ul>
</div>
<div class="section" id="built-in-to-python-interpreter">
<h4>Built-in to Python interpreter<a class="headerlink" href="#built-in-to-python-interpreter" title="Permalink to this headline">¶</a></h4>
<ul>
<li><p class="first">Find the directory where your <code class="docutils literal"><span class="pre">Setup</span></code> file lives (usually in the <code class="docutils literal"><span class="pre">Modules</span></code>
subdirectory) in the Python source hierarchy and copy or symlink the
<code class="docutils literal"><span class="pre">pgmodule.c</span></code> file there.</p>
</li>
<li><p class="first">Add the following line to your ‘Setup’ file:</p>
<div class="highlight-default"><div class="highlight"><pre>_pg pgmodule.c -I$PGINC -I$PSINC -L$PGLIB -lpq
</pre></div>
</div>
<p>where:</p>
<div class="highlight-default"><div class="highlight"><pre><span class="n">PGINC</span> <span class="o">=</span> <span class="n">path</span> <span class="n">to</span> <span class="n">the</span> <span class="n">PostgreSQL</span> <span class="n">client</span> <span class="n">include</span> <span class="n">files</span> <span class="p">(</span><span class="n">see</span> <span class="n">above</span><span class="p">)</span>
<span class="n">PSINC</span> <span class="o">=</span> <span class="n">path</span> <span class="n">to</span> <span class="n">the</span> <span class="n">PostgreSQL</span> <span class="n">server</span> <span class="n">include</span> <span class="n">files</span> <span class="p">(</span><span class="n">see</span> <span class="n">above</span><span class="p">)</span>
<span class="n">PGLIB</span> <span class="o">=</span> <span class="n">path</span> <span class="n">to</span> <span class="n">the</span> <span class="n">PostgreSQL</span> <span class="nb">object</span> <span class="n">code</span> <span class="n">libraries</span> <span class="p">(</span><span class="n">see</span> <span class="n">above</span><span class="p">)</span>
</pre></div>
</div>
<p>Some options may be added to this line:</p>
<div class="highlight-default"><div class="highlight"><pre><span class="o">-</span><span class="n">DNO_DEF_VAR</span> <span class="n">no</span> <span class="n">default</span> <span class="n">variables</span> <span class="n">support</span>
<span class="o">-</span><span class="n">DNO_DIRECT</span> <span class="n">no</span> <span class="n">direct</span> <span class="n">access</span> <span class="n">methods</span>
<span class="o">-</span><span class="n">DNO_LARGE</span> <span class="n">no</span> <span class="n">large</span> <span class="nb">object</span> <span class="n">support</span>
<span class="o">-</span><span class="n">DNO_PQSOCKET</span> <span class="k">if</span> <span class="n">running</span> <span class="n">an</span> <span class="n">older</span> <span class="n">PostgreSQL</span> <span class="p">(</span><span class="n">see</span> <span class="n">above</span><span class="p">)</span>
</pre></div>
</div>
<p>On some systems you may need to include <code class="docutils literal"><span class="pre">-lcrypt</span></code> 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 <code class="docutils literal"><span class="pre">shared</span></code> keyword is
uncommented and add the above line below it. You used to need to install
your shared modules with <code class="docutils literal"><span class="pre">make</span> <span class="pre">sharedinstall</span></code> but this no longer seems
to be true.</p>
</li>
<li><p class="first">Copy <code class="docutils literal"><span class="pre">pg.py</span></code> to the lib directory where the rest of your modules are.
For example, that’s <code class="docutils literal"><span class="pre">/usr/local/lib/Python</span></code> on my system.</p>
</li>
<li><p class="first">Rebuild Python from the root directory of the Python source hierarchy by
running <code 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></code> and <code class="docutils literal"><span class="pre">make</span> <span class="pre">&&</span> <span class="pre">make</span> <span class="pre">install</span></code>.</p>
</li>
<li><p class="first">For more details read the documentation at the top of <code class="docutils literal"><span class="pre">Makefile.pre.in</span></code>.</p>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<p class="logo"><a href="index.html" title="contents/index">
<img class="logo" src="../_static/pygresql.png" alt="Logo"/>
</a></p><div class="sphinxlocaltoc">
<h3><a href="../index.html">Page contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Installation</a><ul>
<li><a class="reference internal" href="#general">General</a></li>
<li><a class="reference internal" href="#installing-with-pip">Installing with Pip</a></li>
<li><a class="reference internal" href="#installing-from-a-binary-distribution">Installing from a Binary Distribution</a></li>
<li><a class="reference internal" href="#installing-from-source">Installing from Source</a><ul>
<li><a class="reference internal" href="#building-and-installing-with-distutils">Building and installing with Distutils</a></li>
<li><a class="reference internal" href="#compiling-manually">Compiling Manually</a><ul>
<li><a class="reference internal" href="#stand-alone">Stand-Alone</a></li>
<li><a class="reference internal" href="#built-in-to-python-interpreter">Built-in to Python interpreter</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div class="sphinxprev">
<h4>Previous page</h4>
<p class="topless"><a href="index.html"
title="Previous page">← The PyGreSQL documentation</a></p>
</div>
<div class="sphinxnext">
<h4>Next page</h4>
<p class="topless"><a href="changelog.html"
title="Next page">→ ChangeLog</a></p>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/contents/install.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="../search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="relbar-bottom">
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> </li>
<li class="right" >
<a href="changelog.html" title="ChangeLog"
>next</a> </li>
<li class="right" >
<a href="index.html" title="The PyGreSQL documentation"
>previous</a> </li>
<li><a href="index.html">PyGreSQL 5.0 documentation</a> »</li>
</ul>
</div>
</div>
<div class="footer" role="contentinfo">
© <a href="../copyright.html">Copyright</a> 2016, The PyGreSQL team.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.1.
</div>
<!-- cloud_sptheme 1.4 -->
</body>
</html>
|