Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I can't seem to be able to get the python ldap module installed on my OS X Mavericks 10.9.1 machine.

Kernel details: uname -a Darwin 13.0.0 Darwin Kernel Version 13.0.0: Thu Sep 19 22:22:27 PDT 2013; root:xnu-2422.1.72~6/RELEASE_X86_64 x86_64

I tried what was suggested here: http://projects.skurfer.com/posts/2011/python_ldap_lion/

But when I try to use pip I get a different error

Modules/LDAPObject.c:18:10: fatal error: 'sasl.h' file not found

*#include sasl.h

I also tried what was suggested here: python-ldap OS X 10.6 and Python 2.6

But with the same error.

I am hoping someone could help me out here.

like image 851
gprx100 Avatar asked Feb 27 '14 20:02

gprx100


5 Answers

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"
like image 150
dnozay Avatar answered Nov 10 '22 20:11

dnozay


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!

like image 32
hharnisc Avatar answered Nov 10 '22 22:11

hharnisc


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.

like image 24
Brian Cline Avatar answered Nov 10 '22 21:11

Brian Cline


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.

like image 5
Mick T Avatar answered Nov 10 '22 20:11

Mick T


I used a combination of posts I found about this problem (including this one) to eventually come up with this (copied from a larger script):

export XC_SDK=$(xcrun --show-sdk-path)
export USR_INC=$XC_SDK/usr/include
export PATH=$USR_INC:$PATH

echo "installing python-ldap"
ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install python-ldap

You can test it with python -c "import ldap"

The main reason I didn't follow the advice of @hharnisc was that on my local machine /usr/local had not moved, so I just temporarily put $XC_SDK before it on the path, and that seems to work.

some sources:
how to install PIL on Macosx 10.9?

like image 1
Peter Hanley Avatar answered Nov 10 '22 21:11

Peter Hanley