Installing python-ldap

Installing from PyPI

The preferred point for downloading the “official” source distribution is the PyPI repository which supports installing via pip. For example:

$ python -m pip install python-ldap

For installing from PyPI, you will need the same Build prerequisites as when installing from source.

We do not currently provide pre-built packages (wheels).

Furthermore, python-ldap requires the modules pyasn1 and pyasn1-modules. pip will install these automatically.

Pre-built Binaries

Because distributions seem to be all over the place, this page tries to list all the current ones we know of.

Note that the python-ldap team is not responsible for the binary packages except the sources you can grab from the PyPI page. Also note that binary packages are most times not up to date. If you experience troubles with a binary package, it would be nice if you try to build a recent version of python-ldap before submitting a bug report to make sure you did not hit a problem already fixed in recent releases.

openSUSE Linux

Ships with python-ldap and there’s an additional download repository which contains builds of latest releases (see also OBS package).

Debian Linux

Have a look into the Debian Package Tracker to get up to date information which versions are available.

Windows

Unofficial packages for Windows are available on Christoph Gohlke’s page.

FreeBSD

The CVS repository of FreeBSD contains the package py-ldap

macOS

You can install directly with pip:

$ xcode-select --install
$ pip install python-ldap \
    --global-option=build_ext \
    --global-option="-I$(xcrun --show-sdk-path)/usr/include/sasl"

Installing from Source

python-ldap is built and installed using the Python setuptools. From a source repository:

$ python -m pip install setuptools
$ python setup.py install

If you have more than one Python interpreter installed locally, you should use the same one you plan to use python-ldap with.

Further instructions can be found in Setuptools documentation.

Build prerequisites

The following software packages are required to be installed on the local system when building python-ldap:

  • Python including its development files
  • C compiler corresponding to your Python version (on Linux, it is usually gcc)
  • OpenLDAP client libs version 2.4.11 or later; it is not possible and not supported to build with prior versions.
  • OpenSSL (optional)
  • Cyrus SASL (optional)
  • Kerberos libraries, MIT or Heimdal (optional)

Alpine

Packages for building:

# apk add build-base openldap-dev python3-dev

CentOS

Packages for building:

# yum groupinstall "Development tools"
# yum install openldap-devel python-devel

Debian

Packages for building and testing:

# apt-get install build-essential python3-dev \
    libldap2-dev libsasl2-dev slapd ldap-utils tox \
    lcov valgrind

Note

On older releases tox was called python-tox.

Fedora

Packages for building and testing:

# dnf install "@C Development Tools and Libraries" openldap-devel \
    python3-devel python3-tox \
    lcov clang-analyzer valgrind

Note

openldap-2.4.45-2 (Fedora 26), openldap-2.4.45-4 (Fedora 27) or newer are required.

setup.cfg

The file setup.cfg allows to set some build and installation parameters for reflecting the local installation of required software packages. Only section [_ldap] is described here. More information about other sections can be found in Setuptools documentation.

library_dirs

Specifies in which directories to search for required libraries.

include_dirs

Specifies in which directories to search for include files of required libraries.

libs

A space-separated list of library names to link to (see Libraries used).

extra_compile_args

Compiler options.

extra_objects

Libraries used

ldap
ldap_r

The LDAP protocol library of OpenLDAP. ldap_r is the reentrant version and should be preferred.

lber

The BER encoder/decoder library of OpenLDAP.

sasl2

The Cyrus-SASL library (optional)

ssl

The SSL/TLS library of OpenSSL (optional)

crypto

The basic cryptographic library of OpenSSL (optional)

Example

The following example is for a full-featured build (including SSL and SASL support) of python-ldap with OpenLDAP installed in a different prefix directory (here /opt/openldap-2.4) and SASL header files found in /usr/include/sasl. Debugging symbols are preserved with compile option -g.

[_ldap]
library_dirs = /opt/openldap-2.4/lib
include_dirs = /opt/openldap-2.4/include /usr/include/sasl

extra_compile_args = -g
extra_objects =

libs = ldap_r lber sasl2 ssl crypto