最近は趣味でも仕事でもMac(OSX)上で開発を行うことが多い。python-ldap を試そうと思い、pyenv 環境に pip でインストールしようとしたところ、インストールに失敗。今回はその解決方法です。
スポンサーリンク
pip で python-ldap を OSX にインストール
先ずは、普通に pip でインストールを実施。
$ pip install python-ldap ・・・ running build_ext building '_ldap' extension clang -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include -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/username/.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 ^ 1 error generated. error: command 'clang' failed with exit status 1 ・・・
sasl.h がないそうです。本当でしょうか?
$ xcrun --show-sdk-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk $ find $(xcrun --show-sdk-path) -name sasl.h /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/sasl/sasl.h
やっぱりありました。
pip install python-ldap \ --global-option=build_ext \ --global-option="-I$(xcrun --show-sdk-path)/usr/include/sasl"
無事インストール完了です。pyenvのインストールのときもパスが通って無くてコンパイルできないことがありました。ライブラリが見つからないときは、落ち着いてXcodeの下確認してみるのは大切かもしれません。