noirello / bonsai

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

Mac mini M1 chip can't import #54

Closed lgphone closed 2 years ago

lgphone commented 2 years ago

uname:

Darwin yangEverdeMac-mini.local 20.6.0 Darwin Kernel Version 20.6.0: Wed Jun 23 00:26:27 PDT 2021; root:xnu-7195.141.2~5/RELEASE_ARM64_T8101 arm64

python version

Python 3.8.11

bonsai version:

bonsai==1.2.1

openldap:

brew list openldap /opt/homebrew/Cellar/openldap/2.5.6/.bottle/etc/ (37 files) /opt/homebrew/Cellar/openldap/2.5.6/bin/ldapadd /opt/homebrew/Cellar/openldap/2.5.6/bin/ldapcompare /opt/homebrew/Cellar/openldap/2.5.6/bin/ldapdelete /opt/homebrew/Cellar/openldap/2.5.6/bin/ldapexop /opt/homebrew/Cellar/openldap/2.5.6/bin/ldapmodify /opt/homebrew/Cellar/openldap/2.5.6/bin/ldapmodrdn /opt/homebrew/Cellar/openldap/2.5.6/bin/ldappasswd /opt/homebrew/Cellar/openldap/2.5.6/bin/ldapsearch /opt/homebrew/Cellar/openldap/2.5.6/bin/ldapurl /opt/homebrew/Cellar/openldap/2.5.6/bin/ldapvc /opt/homebrew/Cellar/openldap/2.5.6/bin/ldapwhoami /opt/homebrew/Cellar/openldap/2.5.6/include/ (10 files) /opt/homebrew/Cellar/openldap/2.5.6/lib/liblber-2.5.0.dylib /opt/homebrew/Cellar/openldap/2.5.6/lib/libldap-2.5.0.dylib /opt/homebrew/Cellar/openldap/2.5.6/lib/pkgconfig/ (2 files) /opt/homebrew/Cellar/openldap/2.5.6/lib/ (4 other files) /opt/homebrew/Cellar/openldap/2.5.6/libexec/slapd /opt/homebrew/Cellar/openldap/2.5.6/sbin/slapacl /opt/homebrew/Cellar/openldap/2.5.6/sbin/slapadd /opt/homebrew/Cellar/openldap/2.5.6/sbin/slapauth /opt/homebrew/Cellar/openldap/2.5.6/sbin/slapcat /opt/homebrew/Cellar/openldap/2.5.6/sbin/slapdn /opt/homebrew/Cellar/openldap/2.5.6/sbin/slapindex /opt/homebrew/Cellar/openldap/2.5.6/sbin/slapmodify /opt/homebrew/Cellar/openldap/2.5.6/sbin/slappasswd /opt/homebrew/Cellar/openldap/2.5.6/sbin/slapschema /opt/homebrew/Cellar/openldap/2.5.6/sbin/slaptest /opt/homebrew/Cellar/openldap/2.5.6/share/man/ (257 files)

when import error:

import bonsai Traceback (most recent call last): File "", line 1, in File "/Users/yangever/PycharmProjects/lpcmdb/venv/lib/python3.8/site-packages/bonsai/init.py", line 3, in from .ldapconnection import LDAPConnection File "/Users/yangever/PycharmProjects/lpcmdb/venv/lib/python3.8/site-packages/bonsai/ldapconnection.py", line 5, in from ._bonsai import ldapconnection, ldapsearchiter ImportError: dlopen(/Users/yangever/PycharmProjects/lpcmdb/venv/lib/python3.8/site-packages/bonsai/_bonsai.cpython-38-darwin.so, 2): Symbol not found: _ldap_create_passwordpolicy_control Referenced from: /Users/yangever/PycharmProjects/lpcmdb/venv/lib/python3.8/site-packages/bonsai/_bonsai.cpython-38-darwin.so Expected in: flat namespace in /Users/yangever/PycharmProjects/lpcmdb/venv/lib/python3.8/site-packages/bonsai/_bonsai.cpython-38-darwin.so

when install whl

pip install ~/Downloads/bonsai-1.2.1-cp38-cp38-macosx_10_14_x86_64.whl

ERROR: bonsai-1.2.1-cp38-cp38-macosx_10_14_x86_64.whl is not a supported wheel on this platform.

final

maybe bonsai not support arm64? but i'am install the openldap, it shoud has lib/so ..etc requirements..

noirello commented 2 years ago

You have to build the package from source on your own. Because afaik none of the used CI platforms supports M1 macOS vms currently, there are no M1 compatible arm64 wheels uploaded to PyPI.

rboixaderg commented 2 years ago

Hi! I try to build the package from source in MacOS M1 but I have still the same error:

I change setup.cfg to:

[build_ext] library_dirs = /opt/homebrew/opt/openldap/lib include_dirs = /opt/homebrew/opt/openldap/include

and then

python setup.py build
python setup.py install

But I have the same error when I try to import bonsai:

Python 3.9.13 (main, Jun 26 2022, 16:38:18) 
[Clang 13.0.0 (clang-1300.0.27.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import bonsai
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/rogerboixaderguell/.pyenv/versions/firaMediterrania/lib/python3.9/site-packages/bonsai-1.4.0-py3.9-macosx-12.2-arm64.egg/bonsai/__init__.py", line 3, in <module>
    from .ldapconnection import LDAPConnection
  File "/Users/rogerboixaderguell/.pyenv/versions/firaMediterrania/lib/python3.9/site-packages/bonsai-1.4.0-py3.9-macosx-12.2-arm64.egg/bonsai/ldapconnection.py", line 5, in <module>
    from bonsai._bonsai import ldapconnection, ldapsearchiter
ImportError: dlopen(/Users/rogerboixaderguell/.pyenv/versions/firaMediterrania/lib/python3.9/site-packages/bonsai-1.4.0-py3.9-macosx-12.2-arm64.egg/bonsai/_bonsai.cpython-39-darwin.so, 0x0002): symbol not found in flat namespace '_ldap_create_passwordpolicy_control'

Python version: 3.9.13 Openldap version: 2.6.3 MacOs version: 12.4

Thanks!

noirello commented 2 years ago

I don't have access to Mac with M1 chip, so I can't really look into it. Could you check that the module linked with the correct libldap lib?

otool -L /Users/rogerboixaderguell/.pyenv/versions/firaMediterrania/lib/python3.9/site-packages/bonsai-1.4.0-py3.9-macosx-12.2-arm64.egg/bonsai/_bonsai.cpython-39-darwin.so
rboixaderg commented 2 years ago

Hi! this is the libldap linked to module

otool -L /Users/rogerboixaderguell/.pyenv/versions/firaMediterrania/lib/python3.9/site-packages/bonsai-1.4.0-py3.9-macosx-12.2-arm64.egg/bonsai/_bonsai.cpython-39-darwin.so
/Users/rogerboixaderguell/.pyenv/versions/firaMediterrania/lib/python3.9/site-packages/bonsai-1.4.0-py3.9-macosx-12.2-arm64.egg/bonsai/_bonsai.cpython-39-darwin.so:
        /System/Library/Frameworks/LDAP.framework/Versions/A/LDAP (compatibility version 1.0.0, current version 2.4.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.100.3)

Actually brew is installed in /opt/homebrew/bin/brew instead of in /usr/local/bin/brew, in my setup.cfg I have this:

library_dirs = /opt/homebrew/opt/openldap/include
include_dirs = /opt/homebrew/opt/openldap/lib

I don't know if this change anything.

Thanks!

noirello commented 2 years ago

It does, the library and include directory paths are switched (you're using the include dir as library_dirs and vice versa).

Probably that's why the module is linked with system provided libldap (which is version 2.4.0) instead of the brew installed one (version 2.6.x).

rboixaderg commented 2 years ago

Oh, excuse me, yes I switched include dir and lib dir, but If I put correctly the error persists, I have 2.6.3 openldap version. I need the 2.4.0 version?

Now the setup.cfg looks like that:

[build_ext]
library_dirs = /opt/homebrew/opt/openldap/lib
include_dirs = /opt/homebrew/opt/openldap/include

brew info openldap

openldap: stable 2.6.3 (bottled) [keg-only]
Open source suite of directory software
https://www.openldap.org/software/
/opt/homebrew/Cellar/openldap/2.6.3 (340 files, 7.8MB)
  Poured from bottle on 2022-07-25 at 10:29:31
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/openldap.rb
License: OLDAP-2.8
==> Dependencies
Required: openssl@1.1 ✔
==> Caveats
openldap is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have openldap first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/openldap/bin:$PATH"' >> ~/.zshrc
  echo 'export PATH="/opt/homebrew/opt/openldap/sbin:$PATH"' >> ~/.zshrc

For compilers to find openldap you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/openldap/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/openldap/include"

For pkg-config to find openldap you may need to set:
  export PKG_CONFIG_PATH="/opt/homebrew/opt/openldap/lib/pkgconfig"

==> Analytics
install: 159,335 (30 days), 464,692 (90 days), 1,724,148 (365 days)
install-on-request: 39,854 (30 days), 122,829 (90 days), 377,934 (365 days)
build-error: 16 (30 days)

Thanks!

noirello commented 2 years ago

No, 2.6.3 should be fine. Which library the module's .so is linked after you uninstalled and rebuilt the module?

rboixaderg commented 2 years ago

After uninstall and rebuild, I have the same library linked to module.

noirello commented 2 years ago

That's odd, usually setting the libraries are enough for the complier to pick up the newer/correct libraries. You could try to set the complier flags just like the brew output suggests it. Also you can force python to build the module with python3 setup.py build -f and then install it with python3 setup.py install.

rboixaderg commented 2 years ago

No changes, still the same lib linked to module. I see that in setup.py there are this line:

if sys.platform == "darwin":
    LIBDIRS.append("/usr/local/lib")
    MACROS.append(("MACOSX", 1))

I change it for:

if sys.platform == "darwin":
    LIBDIRS.append("/opt/homebrew/lib")
    MACROS.append(("MACOSX", 1))

Because in M1 I have libs in there directory, but after that I try to build again and the libraray that linked to module is the same.

rboixaderg commented 1 year ago

Hi! Finally I have been able to install bonsai correctly! I use this command:

brew link openldap --force

This linked openldap libs to /opt/homebrew/lib If we see the build output, we can see that MacOS put system libraries before ours, but not before /opt/homebre/lib.

clang -bundle -undefined dynamic_lookup -L/opt/homebrew/opt/readline/lib -L/opt/homebrew/opt/readline/lib -L/Users/rogerboixaderguell/.pyenv/versions/3.10.3/lib -L/opt/homebrew/opt/xz/lib -L/opt/homebrew/lib -L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib -L/opt/homebrew/opt/readline/lib -L/opt/homebrew/opt/readline/lib -L/Users/rogerboixaderguell/.pyenv/versions/3.10.3/lib -L/opt/homebrew/opt/xz/lib -L/opt/homebrew/lib -L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib -L/opt/homebrew/opt/openssl@3/lib -L/opt/homebrew/opt/openldap/lib -I/opt/homebrew/opt/openssl@3/include -I/opt/homebrew/opt/openldap/include build/temp.macosx-12.4-arm64-3.10/src/_bonsai/bonsaimodule.o build/temp.macosx-12.4-arm64-3.10/src/_bonsai/ldap-xplat.o build/temp.macosx-12.4-arm64-3.10/src/_bonsai/ldapconnection.o build/temp.macosx-12.4-arm64-3.10/src/_bonsai/ldapconnectiter.o build/temp.macosx-12.4-arm64-3.10/src/_bonsai/ldapentry.o build/temp.macosx-12.4-arm64-3.10/src/_bonsai/ldapmodlist.o build/temp.macosx-12.4-arm64-3.10/src/_bonsai/ldapsearchiter.o build/temp.macosx-12.4-arm64-3.10/src/_bonsai/utils.o -L/opt/homebrew/opt/openldap/lib -L/opt/homebrew/opt/openldap/lib -lldap -llber -o build/lib.macosx-12.4-arm64-3.10/bonsai/_bonsai.cpython-310-darwin.so

Thanks for all!