在Mac OS X Mavericks上安装py ldap(缺少sasl.h)

2024-05-16 09:11:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我似乎无法在我的OSX Mavericks 10.9.1机器上安装PythonLDAP模块。

内核详细信息: 找到对应内核版本 Darwin 13.0.0 Darwin内核版本13.0.0:Thu 9月19日22:22:27 PDT 2013;根目录:xnu-2422.1.72~6/RELEASE_X86_64x86_64

我尝试了这里的建议: http://projects.skurfer.com/posts/2011/python_ldap_lion/

但是当我尝试使用pip时,我得到了一个不同的错误

Modules/LDAPObject.c:18:10:致命错误:找不到“sasl.h”文件

*#包括sasl.h

我也尝试了这里的建议: python-ldap OS X 10.6 and Python 2.6

但同样的错误。

我希望有人能帮我。


Tags: 模块版本机器错误详细信息ldap内核建议
3条回答

使用@hharnisc和@mick-t答案中的片段。

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

解决方法
/usr/include似乎已移动

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

现在运行pip安装!

在我的特殊情况下,我不能简单地使用其他答案中指出的pip参数,因为我将它与tox一起用于从requirements.txt文件安装依赖项,并且我需要tox.In I与非Mac环境保持兼容。

我可以用更简单的方式解决这个问题:导出CFLAGS,这样它就为Xcode已经安装的sasl头添加了一个include路径:

$ 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

根据您是否使用任何用户空间友好的Python工具(我使用pyenv),您可能必须在pip命令前面加上sudo

相关问题 更多 >