noirello / bonsai

Simple Python 3 module for LDAP, using libldap2 and winldap C libraries.
MIT License
117 stars 33 forks source link

Unable to import on Mac OS X 10.10 #4

Closed kradalby closed 8 years ago

kradalby commented 9 years ago

Hi

This library looks pretty neat, but when i installed it and tried to import it on OS X i received the following import error:

Python 3.4.3 (default, Jul 13 2015, 12:18:23)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyldap
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/kradalby/git/garru/env/lib/python3.4/site-packages/pyldap/__init__.py", line 3, in <module>
    from pyldap.ldapconnection import LDAPConnection
  File "/Users/kradalby/git/garru/env/lib/python3.4/site-packages/pyldap/ldapconnection.py", line 1, in <module>
    from pyldap._cpyldap import _LDAPConnection
ImportError: dlopen(/Users/kradalby/git/garru/env/lib/python3.4/site-packages/pyldap/_cpyldap.so, 2): Symbol not found: _ldap_control_find
  Referenced from: /Users/kradalby/git/garru/env/lib/python3.4/site-packages/pyldap/_cpyldap.so
  Expected in: flat namespace
 in /Users/kradalby/git/garru/env/lib/python3.4/site-packages/pyldap/_cpyldap.so

I guess it may be a compile error?

OS X version is 10.10.4 Python 3.4.3

I have not installed any additional LDAP libs, or anything, this may be the problem?

Install command:

pip install git+https://github.com/Noirello/PyLDAP.git

I will be happy to provide any additional information if needed.

noirello commented 9 years ago

Well, the openldap (and sasl2) headers are needed for compiling, but I guess you would have noticed in error messages if they were missing after ran pip.

I did some research, and it seems that the pre-compiled OpenLDAP library on OS X somehow doesn't have an ldap_control_find, but only the deprecated ldap_find_control function. It's weird.

For temporally solution I can add this function manually, if the platform is OS X, but for testing I would like to ask for your help, because I don't have an available OS X system.

Edit: the modification is uploaded on the dev branch. (don't forget to leave the PyLDAP folder after run setup.py install to avoid that the interpreter try to load the local pyldap dir, instead of the one in the site-packages folder)

kradalby commented 9 years ago

I have limited C/C++ knowledge, but i have noe problem with trying to use the packages and provide you with the result/output.

I pulled down the dev branch now, and when trying to compile, i received the following error:

$ python setup.py install
running install
running bdist_egg
running egg_info
creating pyldap.egg-info
writing top-level names to pyldap.egg-info/top_level.txt
writing dependency_links to pyldap.egg-info/dependency_links.txt
writing pyldap.egg-info/PKG-INFO
writing manifest file 'pyldap.egg-info/SOURCES.txt'
reading manifest file 'pyldap.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching '*.c' under directory 'tests'
warning: no files found matching '*.h' under directory 'tests'
warning: no files found matching '*.css' under directory 'docs'
writing manifest file 'pyldap.egg-info/SOURCES.txt'
installing library code to build/bdist.macosx-10.10-x86_64/egg
running install_lib
running build_py
creating build
creating build/lib.macosx-10.10-x86_64-3.4
creating build/lib.macosx-10.10-x86_64-3.4/pyldap
copying pyldap/__init__.py -> build/lib.macosx-10.10-x86_64-3.4/pyldap
copying pyldap/errors.py -> build/lib.macosx-10.10-x86_64-3.4/pyldap
copying pyldap/ldapclient.py -> build/lib.macosx-10.10-x86_64-3.4/pyldap
copying pyldap/ldapconnection.py -> build/lib.macosx-10.10-x86_64-3.4/pyldap
copying pyldap/ldapdn.py -> build/lib.macosx-10.10-x86_64-3.4/pyldap
copying pyldap/ldapentry.py -> build/lib.macosx-10.10-x86_64-3.4/pyldap
copying pyldap/ldapurl.py -> build/lib.macosx-10.10-x86_64-3.4/pyldap
running build_ext
building 'pyldap._cpyldap' extension
creating build/temp.macosx-10.10-x86_64-3.4
creating build/temp.macosx-10.10-x86_64-3.4/pyldap
clang -Wno-unused-result -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/Cellar/python3/3.4.3_2/Frameworks/Python.framework/Versions/3.4/include/python3.4m -c pyldap/pyldapmodule.c -o build/temp.macosx-10.10-x86_64-3.4/pyldap/pyldapmodule.o
In file included from pyldap/pyldapmodule.c:3:
In file included from pyldap/ldapconnection.h:7:
pyldap/ldap-xplat.h:14:1: error: unknown type name 'LDAPControl'
LDAPControl *ldap_control_find(const char *oid, LDAPControl **ctrls, LDAPControl ***nextctrlp);
^
pyldap/ldap-xplat.h:14:49: error: unknown type name 'LDAPControl'
LDAPControl *ldap_control_find(const char *oid, LDAPControl **ctrls, LDAPControl ***nextctrlp);
                                                ^
pyldap/ldap-xplat.h:14:70: error: unknown type name 'LDAPControl'
LDAPControl *ldap_control_find(const char *oid, LDAPControl **ctrls, LDAPControl ***nextctrlp);
                                                                     ^
3 errors generated.
error: command 'clang' failed with exit status 1
noirello commented 9 years ago

Thank you, I really appreciate your help.

I made a clumsy mistake and put the declaration before the includes. I fixed and committed into the dev branch.

matepeter90 commented 9 years ago

Hello,

I tried to build the module from the dev branch, but there are still some errors:

Python 3.4.3 (default, Jul 13 2015, 12:18:23)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyldap
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/max/work/PyLDAP/venv/lib/python3.4/site-packages/pyldap-0.7.5-py3.4-macosx-10.10-x86_64.egg/pyldap/__init__.py", line 3, in <module>
    from pyldap.ldapconnection import LDAPConnection
  File "/Users/max/work/PyLDAP/venv/lib/python3.4/site-packages/pyldap-0.7.5-py3.4-macosx-10.10-x86_64.egg/pyldap/ldapconnection.py", line 1, in <module>
    from pyldap._cpyldap import _LDAPConnection
ImportError: dlopen(/Users/max/work/PyLDAP/venv/lib/python3.4/site-packages/pyldap-0.7.5-py3.4-macosx-10.10-x86_64.egg/pyldap/_cpyldap.so, 2): Symbol not found: _ldap_sasl_interactive_bind

After a while I found this page (http://projects.skurfer.com/posts/2011/python_ldap_lion/) and it describes that the OSX uses really old LDAP libraries, which does not have the missing _ldap_sasl_interactive_bind function

I checked and it's still just 2.4.0 in OS X 10.10.4:

% otool -L /usr/lib/libldap_r.dylib
/usr/lib/libldap_r.dylib:
    /System/Library/Frameworks/LDAP.framework/Versions/A/LDAP (compatibility version 1.0.0, current version 2.4.0)
    /usr/lib/libsasl2.2.dylib (compatibility version 3.0.0, current version 3.15.0)
    /System/Library/Frameworks/Security.framework/Versions/A/Security (compatibility version 1.0.0, current version 57031.20.16)
    /System/Library/PrivateFrameworks/CoreDaemon.framework/Versions/B/CoreDaemon (compatibility version 3.0.0, current version 3.0.0)
    /usr/lib/libresolv.9.dylib (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1153.15.0)
    /System/Library/Frameworks/SystemConfiguration.framework/Versions/A/SystemConfiguration (compatibility version 1.0.0, current version 699.1.5)
    /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0)

There is a workaround also on the page (I didn't try it), but you can patch'n'hack new OpenLDAP libraries into the OS X and build the module against them.

kradalby commented 9 years ago

yeah, i just found that page too.

I think that for me personally, i will just develop in a VM, since i am going to deploy on Linux anyways.

If i can help with any more OS X testing, just ask. But i dont think i can help with any of the C stuff :/

noirello commented 9 years ago

Testers are always more than welcome. :)

I've looked into it, and it seems at least version 2.4.24 is needed for the module (release date is around 2011). I'm going to check that hack for OS X somehow, and if I succeed, I will update the documentation about Mac OS X install. But it will take time, so probably good idea to use Linux for now.

kradalby commented 9 years ago

The new OS X release is around the corner, one can hope that they may up the version a little :P

noirello commented 8 years ago

Well, it took me awhile (sorry about the delay), but recently I managed to run a Mac OS X (10.11) in VirtualBox, and tested out the hack linked earlier. It works for me.

Updated the docs based on the blog post about Mac OS X install.

Also, thanks to this module, I will be able to create Mac OS X wheels for the next release, that will include the newer OpenLDAP libraries, so it will be not necessary to install them manually.

Update: uploaded a wheel for Mac based on the latest dev branch for testing purposes.