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.


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


The CVS repository of FreeBSD contains the package py-ldap


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 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)


Packages for building:

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


Packages for building:

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


Packages for building and testing:

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


On older releases tox was called python-tox.


Packages for building and testing:

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


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


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.


Specifies in which directories to search for required libraries.


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


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


Compiler options.


Libraries used


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


The BER encoder/decoder library of OpenLDAP.


The Cyrus-SASL library (optional)


The SSL/TLS library of OpenSSL (optional)


The basic cryptographic library of OpenSSL (optional)


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.

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