Installing py-ldap on Mac OS X Mavericks (missing sasl.h)

In my particular case, I couldn't simply use the pip arguments noted in other answers because I'm using it with tox to install dependencies from a requirements.txt file, and I need my tox.ini to remain compatible with non-Mac environments.

I was able to resolve this in much simpler fashion: exporting CFLAGS such that it adds an include path to the sasl headers already installed by Xcode:

$ pip install python-ldap
    ...
    building '_ldap' extension
    creating build/temp.macosx-10.10-x86_64-2.7
    creating build/temp.macosx-10.10-x86_64-2.7/Modules
    clang -fno-strict-aliasing -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -DHAVE_SASL -DHAVE_TLS -DHAVE_LIBLDAP_R -DHAVE_LIBLDAP_R -DLDAPMODULE_VERSION=2.4.19 -IModules -I/opt/openldap-RE24/include -I/usr/include/sasl -I/usr/include -I/Users/bc/.pyenv/versions/2.7.10/include/python2.7 -c Modules/LDAPObject.c -o build/temp.macosx-10.10-x86_64-2.7/Modules/LDAPObject.o
    Modules/LDAPObject.c:18:10: fatal error: 'sasl.h' file not found
    #include <sasl.h>
             ^
    1 error generated.
    error: command 'clang' failed with exit status 1

$ export CFLAGS="-I$(xcrun --show-sdk-path)/usr/include/sasl"

$ pip install python-ldap
...
Successfully installed python-ldap-2.4.19

Depending on whether or not you use any userspace-friendly Python tools (I use pyenv), you may have to prefix your pip commands with sudo.


I had the same problem. I'm using Macports on my Mac and I have cyrus-sasl2 installed which provides sasl.h in /opt/local/include/sasl/. You can pass options to build_ext using pip's global-option argument. To pass the include PATH to /opt/local/include/sasl/sasl.h run pip like this:

pip install python-ldap --global-option=build_ext --global-option="-I/opt/local/include/sasl"

Alternatively you could point it to whatever the output from xcrun --show-sdk-path provides. On my box that's: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk

Then you need to determine the PATH to the sasl header files. For me that's:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/sasl/

Let me know if that helps or you need a hand.


using pieces from both @hharnisc and @mick-t answers.

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

A workaround
/usr/include appears to have moved

$ xcrun --show-sdk-path    
$ sudo ln -s <the_path_from_above_command>/usr/include /usr/include

Now run pip install!