在Mac OS X Mavericks中安装py-ldap(缺失sasl.h)

时间:2022-09-19 00:29:21

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

我似乎无法将python ldap模块安装到我的OS X Mavericks 10.9.1机器上。

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

内核细节:uname - Darwin 13.0.0 Darwin内核版本13.0.0:Thu Sep 19 22:27 PDT 2013;根: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/

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

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

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

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

模块/ LDAPObject。c:18:致命错误:“sasl。h的文件未找到

*#include sasl.h

* # include sasl.h

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

我还尝试了这里的建议:Python -ldap OS X 10.6和Python 2.6

But with the same error.

但同样的错误。

I am hoping someone could help me out here.

我希望有人能帮助我。

5 个解决方案

#1


86  

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

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

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

#2


31  

A workaround
/usr/include appears to have moved

一个工作区/usr/include似乎已经移动

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

Now run pip install!

现在运行pip安装!

#3


15  

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.

在我的特殊情况下,我不能简单地使用其他答案中提到的pip参数,因为我使用它与tox来从需求中安装依赖关系。txt文件,我需要毒气。保持与非mac环境的兼容性。

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:

我能够以更简单的方式解决这个问题:输出CFLAGS,这样它就添加了一个包含Xcode已经安装的sasl头的路径:

$ 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.

取决于您是否使用任何对用户空间友好的Python工具(我使用pyenv),您可能需要在pip命令前面加上sudo。

#4


5  

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:

我也有同样的问题。我在Mac上使用Macports,并安装了cyruss -sasl2,它提供了sasl。在/ opt /地方/ h包括/ sasl /。您可以使用pip的全局选项参数将选项传递给build_ext。传递包含路径到/opt/local/include/sasl/sasl。h运行pip如下:

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

pip安装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

或者,您可以将它指向xcrun的输出——显示-sdk-path提供的任何输出。在我的框中有:/ application /Xcode.app/ content /Developer/ platform/ MacOSX.platform/Developer/SDKs/ macosx10.9 sdk

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

然后需要确定sasl头文件的路径。对我来说这是:

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

/应用程序/ xcode /内容/开发/平台/ MacOSX.platform /开发/ sdk / MacOSX10.9.sdk / usr / include / sasl /

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

如果有帮助的话请告诉我,或者你需要帮忙。

#5


0  

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"

您可以使用python -c“导入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.

我没有遵循@hharnisc的建议的主要原因是,在我的本地机器/usr/local中没有移动,所以我只是暂时将$XC_SDK放在路径上,这似乎起作用了。

some sources:
how to install PIL on Macosx 10.9?

一些资源:如何在Macosx 10.9上安装PIL ?

#1


86  

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

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

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

#2


31  

A workaround
/usr/include appears to have moved

一个工作区/usr/include似乎已经移动

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

Now run pip install!

现在运行pip安装!

#3


15  

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.

在我的特殊情况下,我不能简单地使用其他答案中提到的pip参数,因为我使用它与tox来从需求中安装依赖关系。txt文件,我需要毒气。保持与非mac环境的兼容性。

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:

我能够以更简单的方式解决这个问题:输出CFLAGS,这样它就添加了一个包含Xcode已经安装的sasl头的路径:

$ 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.

取决于您是否使用任何对用户空间友好的Python工具(我使用pyenv),您可能需要在pip命令前面加上sudo。

#4


5  

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:

我也有同样的问题。我在Mac上使用Macports,并安装了cyruss -sasl2,它提供了sasl。在/ opt /地方/ h包括/ sasl /。您可以使用pip的全局选项参数将选项传递给build_ext。传递包含路径到/opt/local/include/sasl/sasl。h运行pip如下:

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

pip安装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

或者,您可以将它指向xcrun的输出——显示-sdk-path提供的任何输出。在我的框中有:/ application /Xcode.app/ content /Developer/ platform/ MacOSX.platform/Developer/SDKs/ macosx10.9 sdk

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

然后需要确定sasl头文件的路径。对我来说这是:

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

/应用程序/ xcode /内容/开发/平台/ MacOSX.platform /开发/ sdk / MacOSX10.9.sdk / usr / include / sasl /

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

如果有帮助的话请告诉我,或者你需要帮忙。

#5


0  

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"

您可以使用python -c“导入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.

我没有遵循@hharnisc的建议的主要原因是,在我的本地机器/usr/local中没有移动,所以我只是暂时将$XC_SDK放在路径上,这似乎起作用了。

some sources:
how to install PIL on Macosx 10.9?

一些资源:如何在Macosx 10.9上安装PIL ?