- Installing python-ldap¶
- Installing from PyPI¶
- Pre-built Binaries¶
- openSUSE Linux¶
- Debian Linux¶
- Windows¶
- FreeBSD¶
- macOS¶
- Installing from Source¶
- Build prerequisites¶
- Installing python-ldap¶
- Installing from PyPI¶
- Pre-built Binaries¶
- openSUSE Linux¶
- Debian Linux¶
- Windows¶
- FreeBSD¶
- Mac OS X¶
- Installing from Source¶
- Build prerequisites¶
- Sidebar
- Search
- Recent Posts
- Archives
- Categories
- Installing python-ldap on Windows 7 64bit
- Installation and configuration¶
- Installation with a package manager¶
- Importing objects and constants¶
- Library errors¶
- How to install python-ldap on a python 2.7 virtualenv on windows without compiling
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:
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:
Installing from Source¶
python-ldap is built and installed using the Python setuptools. From a source repository:
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 version 2.7, or 3.4 or later 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)
Installing python-ldap¶
You are reading documentation for an unreleased version.
Following these instructions will currently get you version 2.5.2, which does not support Python 3.
Installing from PyPI¶
The preferred point for downloading the “official” source distribution is the PyPI repository which supports installing via pip. For example:
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
Mac OS X¶
You can install directly with pip:
Installing from Source¶
python-ldap is built and installed using the Python setuptools. From a source repository:
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 version 2.7, or 3.3 or later 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)
Sidebar
Search
Recent Posts
Archives
Categories
Installing python-ldap on Windows 7 64bit
Last updated on 2 April 2015
TL;DR: Architecture is important (duh), download the 64bit exe from here.
I recently had a horrendous time trying to install python-ldap on Windows 7 64bit so I decided to write a short post for when my future self needs to install it again in the hope that it will go much more smoothly.
As it turns out I missed one key piece of information, the “ preferred point for downloading the ‘official’ source distribution is now the PyPI repository which supports installing via setuptools ” (http://www.python-ldap.org/download.shtml) BUT this only has 32bit versions, not 64bit!
Therefore installing using pip or the exe fails (obvious in hindsight).
Here are some of the super helpful error message I encountered while I epically failed to take architectures into account:
1) Installing using pip (pip install python-ldap) requires Visual C++ 2008 Express Edition installed, which I didn’t have so resulted in:
To fix, install it free from Microsoft here because it will be required for other modules in the future. Then read 2).
2) Installing using pip (pip install python-ldap) tries to install a 32bit version which isn’t much use when the OS and Python interpreter are 64bit so results in:
To fix: there is not a 64bit version in the pip repo as far as I am aware – skip to the punch line below.
3) Installing using the officially distributed executable on PyPI failed to find my Python install in the registry and gave me this error:
I use ActiveState Python because it comes with pywin32 but apparently it didn’t put the entry in the registry. Looking at the documentation afterwards it appears as though the installer didn’t run with admin privileges and therefore created entries under KEY_CURRENT_USER and not under HKEY_LOCAL_MACHINE.
4) After fixing 3) the exe was able to complete installation (and for a few brief moments I was happy…), but when I tried to import the module it failed with this error:
This is once again because of an architecture mismatch, my Python interpreter is 64bit but the module is 32bit.
After a cup of tea I noticed that the architecture problem and found the alternative installers by Christoph Gohlke here. (The python-ldap download page links to the maintainer’s (Waldemar Osuch) webpage which links to Christoph Gohlke’s page.)
I was then able to download and install the 64bit version with no problems.
As always, if you have any comments or suggestions please feel free to get in touch.
Installation and configuration¶
Installation is straightforward and can be done via a package manager or from the source.
Installation with a package manager¶
You need the pip package (or another package manager that can download and install from pyPI) to install ldap3. Then you can download and install the ldap3 library directly from pyPI:
This library has only one dependence on the pyasn1 module, You can install it or let the installer do it for you.
If you need to access a server with the Kerberos SASL authentication mechanism you must install the gssapi package.
ldap3 includes a backport (from Python 3.4.3) of ssl.check_hostnames to be used on older (version get_config_parameter() and set_config_parameter() functions in the ldap3 namespace to get and set the configurable parameters at runtime.
Importing objects and constants¶
All objects and constants needed to use the ldap3 library can be imported from the ldap3 namespace:
Library errors¶
You can deal with errors in two different ways. By default in synchronous strategies each LDAP operation returns a True/False value that specify if the operation has been successful or not. In case of failures you can check the error description in the `last_error` attribute of the Connection object. In some cases an exception of the custom hierarchy starting from the `LDAPExceptionError` class is raised with a description of the error condition in the args attribute.
If you prefer to deal always with Exceptions you can set the raise_exceptions attribute to True in the Connection object definition. From now on the Connection will raise exceptions for all operations that return result codes different from RESULT_SUCCESS , RESULT_COMPARE_FALSE , RESULT_COMPARE_TRUE , RESULT_REFERRAL .
Communication exceptions have multiple inheritance either from `LDAPCommunicationError` and the specific socket exception.
Exceptions are defined in the ldap3.core.exceptions package.
© Copyright 2020, Giovanni Cannata Revision 78c449dd .
How to install python-ldap on a python 2.7 virtualenv on windows without compiling
I am using Windows as my main python 2.7 development environment and I want to install python-ldap on a virtual environment.
The python-ldap package needs compiling 🙁 and of course I can’t compile it in my environment. So I tried finding binaries in order to install them in my virtual environment through easy_install (FYI you can do easy_install package.exe and the package will be installed). I found the distributed binaries here: https://pypi.python.org/pypi/python-ldap/
Unfortunately, they give only .msi packages for python 2.7 . Why do people use .msi ? MSI CANNOT BE INSTALLED THROUGH easy_install. I HATE MSI %$#$^#$^#$
Yes I can install the .msi package by executing it but it will be installed in the global python packages and not on my virtual environment!
Please, can anybody help me ? I remember having this exact problem in a previous project and I had to develop it outside of a virtual environment — but I cannot do this now 🙁
Update: I installed python-ldap system-wide and copied the directories ldap and python_ldap-2.4.10-py2.7.egg-info from PYTHON_GLOBAL\Lib\site-packages to VIRTUALENV\Lib\site-packages and seems to be working now. However I really don’t like that solution so I won’t answer my question with that. Also, Alexander’s comment on recreating my virtualenv with —system-site-packages probably will be working but this means that I’d need to uninstall a lot of my global packages packages and then install again my virtual packages etc and in general it’s not DRY 🙁
Update 2: After trying cgohlke’s suggestion, I saw that the contents of the MSI were the two directories I mentioned above along with the files dsml.py, ldapurl.py and ldif.py. So I also copied this to my VIRTUALENV\Lib\site-packages. Now I believe that the installation is ok :). But I believe that cgohlke’s is the best one — just use msiexec.exe to extract the contents of the msi directly to your VIRTUALENV.
gohlke/pythonlibs/#python-ldap. In there you will be able to find .EXE install packages for python-ldap and LOTS of others. So finally by downloading these you’ll be able to easy_install them in your virtualenv!