File: install.rst

package info (click to toggle)
psycopg3 3.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,836 kB
  • sloc: python: 46,657; sh: 403; ansic: 149; makefile: 73
file content (276 lines) | stat: -rw-r--r-- 8,930 bytes parent folder | download
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
.. _installation:

Installation
============

In short, if you use one of the :ref:`supported systems<supported-systems>`,
run::

    pip install --upgrade pip
    pip install "psycopg[binary]"

and you should be :ref:`ready to start <module-usage>`. Read further for
alternative ways to install.

.. note::
   Fun fact: there is no ``psycopg3`` package, only ``psycopg``!


.. _supported-systems:

Supported systems
-----------------

The Psycopg version documented here has *official and tested* support for:

- Python: from version 3.10 to 3.14

  - Python 3.8 and 3.9 are supported before Psycopg 3.3
  - Python 3.7 is supported before Psycopg 3.2
  - Python 3.6 is supported before Psycopg 3.1

- PyPy: from version 3.10 to 3.11

  - PyPy 3.9 is supported before Psycopg 3.3
  - **Note:** Only the pure Python installation is currently supported.

- PostgreSQL: from version 10 to 18

  - **Note:** PostgreSQL `currently supported release`__ are actively tested
    in the CI. Out-of-support releases are supported on a best-effort basis.

- OS: Linux, macOS, Windows

- Pip: 20.3 or newer

.. __: https://www.postgresql.org/support/versioning/

The tests to verify the supported systems run in `Github workflows`__:
anything that is not tested there is not officially supported. This includes:

.. __: https://github.com/psycopg/psycopg/actions

- Unofficial Python distributions such as Conda;
- Alternative PostgreSQL implementation;
- Other platforms such as BSD or Solaris.

If you use an unsupported system, things might work (because, for instance, the
database may use the same wire protocol as PostgreSQL) but we cannot guarantee
the correct working or a smooth ride.


.. _install-grid:

What to install?
----------------

There are a few different options to install Psycopg 3. This is a quick
summary of their differences; follow the links for more details.

.. list-table::
   :header-rows: 1

   * - Installation Option
     - Command
     - Description
     - Perfor­mance
     - Needs Local libpq?
     - Needs Build Tools?

   * - :ref:`binary-installation` (recommended for most users)
     - ``pip install psycopg[binary]``
     - Precompiled C extensions, packaged with client lbiraries.
     - 🐇 Fast
     - ❌ No
     - ❌ No

   * - :ref:`local-installation`
     - ``pip install psycopg[c]``
     - Builds C extensions from source.
       Requires build tools and client libraries.
     - 🐇 Fast
     - ✅ Yes
     - ✅ Yes

   * - :ref:`pure-python-installation`
     - ``pip install psycopg``
     - Pure Python implementation only. Requires client libraries.
     - 🐢 Slow
     - ✅ Yes
     - ❌ No


.. _binary-installation:

Binary installation
-------------------

The quickest way to start developing with Psycopg 3 is to install the binary
packages by running::

    pip install "psycopg[binary]"

This will install a self-contained package with all the libraries needed.
If you are coming from Psycopg 2, this is the equivalent of installing
the ``psycopg2-binary`` package.

.. seealso::

    Did Psycopg 3 install ok? Great! You can now move on to the :ref:`basic
    module usage <module-usage>` to learn how it works.

    Keep on reading if the above method didn't work and you need a different
    way to install Psycopg 3.

    For further information about the differences between the packages see
    :ref:`pq-impl`.

If your platform is not supported, or if the libpq packaged is not suitable,
you should proceed to a :ref:`local installation <local-installation>` or a
:ref:`pure Python installation <pure-python-installation>`.

.. note::

    Binary packages are produced on a best-effort basis; the supported
    platforms depend on the CI runners available to build the
    packages. This means that:

    - binary packages for a new version of Python are made available once
      the runners used for the build support it. You can check the
      `psycopg-binary PyPI files`__ to verify whether your platform is
      supported;

    - the libpq version included in the binary packages depends on the version
      available on the runners. You can use the `psycopg.pq.version()`
      function and `~psycopg.pq.__build_version__` constant to infer the
      features available.

    .. __: https://pypi.org/project/psycopg-binary/#files


.. warning::

    - Starting from Psycopg 3.1.20, ARM64 macOS binary packages (i.e. for
      Apple M1 machines) are no more available for macOS versions before 14.0.
      Please upgrade your OS to at least 14.0 or use a :ref:`local
      <local-installation>` or a :ref:`Python <pure-python-installation>`
      installation.

    - The binary installation is not supported by PyPy.



.. _local-installation:

Local installation
------------------

A "Local installation" results in a performing and maintainable library. The
library will include the speed-up C module and will be linked to the system
libraries (``libpq``, ``libssl``...) so that system upgrade of libraries will
upgrade the libraries used by Psycopg 3 too. This is the preferred way to
install Psycopg for a production site.

In order to perform a local installation you need some prerequisites:

- a C compiler,
- Python development headers (e.g. the ``python3-dev`` package).
- PostgreSQL client development headers (e.g. the ``libpq-dev`` package).
- The :program:`pg_config` program available in the :envvar:`PATH`.

You **must be able** to troubleshoot an extension build, for instance you must
be able to read your compiler's error message. If you are not, please don't
try this and use the :ref:`binary-installation` instead.

If your build prerequisites are in place you can run::

    pip install "psycopg[c]"

This will install a self-contained package with all the libraries needed.
If you are coming from Psycopg 2, this is the equivalent of installing
the ``psycopg2`` package, both in terms of build requirements and system
dependencies at runtime.

.. warning::

   The local installation is not supported by PyPy.


.. _pure-python-installation:

Pure Python installation
------------------------

If you simply install::

    pip install psycopg

without ``[c]`` or ``[binary]`` extras you will obtain a pure Python
implementation. This is particularly handy for debugging and hacking.

.. warning::

   The pure Python installation is much slower than the
   :ref:`binary-installation` or :ref:`local-installation`. It is likely
   sufficient for local developments or small tasks but, for production loads,
   you might want to install one of the speed-up extensions too.

In order to use the pure Python installation you will need the ``libpq``
PostgreSQL client library installed on your client (which will be imported
dynamically via `ctypes`); for example on Debian systems you will probably
need::

    sudo apt install libpq5

If you are not able to fulfill this requirement please use a
:ref:`binary-installation`, which packages its own copy of the ``libpq``.

.. note::

    The ``libpq`` is the client library also used by :program:`psql`, the
    PostgreSQL command line client, to connect to the database.  On most
    systems, installing :program:`psql` will install the ``libpq`` too as a
    dependency.


.. _pool-installation:

Installing the connection pool
------------------------------

The :ref:`Psycopg connection pools <connection-pools>` are distributed in a
separate package from the `!psycopg` package itself, in order to allow a
different release cycle.

In order to use the pool you must install the ``pool`` extra, using ``pip
install "psycopg[pool]"``, or install the `psycopg_pool` package separately,
which would allow to specify the release to install more precisely.


.. _install-dependencies:

Handling dependencies
---------------------

If you need to specify your project dependencies (for instance in a
``requirements.txt`` file, ``setup.py``, ``pyproject.toml`` dependencies...)
you should probably specify one of the following:

- If your project is a library, add a dependency on ``psycopg``. This will
  make sure that your library will have the ``psycopg`` package with the right
  interface and leaves the possibility of choosing a specific implementation
  to the end user of your library.

- If your project is a final application (e.g. a service running on a server)
  you can require a specific implementation, for instance ``psycopg[c]``,
  after you have made sure that the prerequisites are met (e.g. the depending
  libraries and tools are installed in the host machine).

In both cases you can specify which version of Psycopg to use using
`requirement specifiers`__.

.. __: https://pip.pypa.io/en/stable/reference/requirement-specifiers/

If you want to make sure that a specific implementation is used you can
specify the :envvar:`PSYCOPG_IMPL` environment variable: importing the library
will fail if the implementation specified is not available. See :ref:`pq-impl`.