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:
error: Unable to find vcvarsall.bat
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:
Python version 2.7 required, which was not found in the registry.
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:
ImportError: DLL load failed: %1 is not a valid Win32 application
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.