Skip to content

ImportError on MacOS 10.15.5 #359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
OutOfFocus4 opened this issue Jun 20, 2020 · 11 comments · Fixed by #360
Closed

ImportError on MacOS 10.15.5 #359

OutOfFocus4 opened this issue Jun 20, 2020 · 11 comments · Fixed by #360

Comments

@OutOfFocus4
Copy link

If you found a bug in python-ldap, or would request a new feature,
this is the place to let us know.

Please describe the issue and your environment here.


Issue description:

After installing python-ldap 3.3.0 on my iMac, it raises an ImportError whenever I try to import it.

Steps to reproduce:

cd /tmp
python3 -m venv test
source test/bin/activate
pip install -U pip setuptools
pip install python-ldap
python -c 'import ldap'

Output:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/private/tmp/test/lib/python3.7/site-packages/ldap/__init__.py", line 34, in <module>
    import _ldap
ImportError: dlopen(/private/tmp/test/lib/python3.7/site-packages/_ldap.cpython-37m-darwin.so, 2): Symbol not found: _ldap_init_fd
  Referenced from: /private/tmp/test/lib/python3.7/site-packages/_ldap.cpython-37m-darwin.so
  Expected in: flat namespace
 in /private/tmp/test/lib/python3.7/site-packages/_ldap.cpython-37m-darwin.so

Operating system: MacOS 10.15.5 (Catalina)

Python version: CPython 3.7.7 (installed with Homebrew)

python-ldap version: 3.3.0

@tiran
Copy link
Member

tiran commented Jun 20, 2020

Symbol not found: _ldap_init_fd points to a new feature that was introduced a couple of weeks ago. What's your OpenLDAP libdap version? Are you using libldap from homebrew or from macOS?

@OutOfFocus4
Copy link
Author

I am using the MacOS system libldap. According to the man page, it is OpenLDAP 2.4.28.

tiran added a commit to tiran/python-ldap that referenced this issue Jun 20, 2020
macOS system libldap 2.4.28 does not have ldap_init_fd symbol. Disable
initialize_fd when Apple libldap 2.4.28 is detected.

Also run some macOS tests on Travis CI. Since the SDK does not ship
slapd, testing is rather limited.

Fixes: python-ldap#359
Signed-off-by: Christian Heimes <cheimes@redhat.com>
@tiran
Copy link
Member

tiran commented Jun 20, 2020

Thanks for the information, PR #360 should fix the problem.

@encukou can you do a 3.3.1 release on Monday?

tiran added a commit to tiran/python-ldap that referenced this issue Jun 22, 2020
macOS system libldap 2.4.28 does not have ldap_init_fd symbol. Disable
initialize_fd when Apple libldap 2.4.28 is detected.

Also run some macOS tests on Travis CI. Since the SDK does not ship
slapd, testing is rather limited.

Fixes: python-ldap#359
Signed-off-by: Christian Heimes <cheimes@redhat.com>
@flymg
Copy link

flymg commented Jun 27, 2020

until merge, using python-ldap==3.2.0 is the workaround

@tiran
Copy link
Member

tiran commented Jun 27, 2020

I recommend to use python-ldap!=3.3.0 instead. The requirements blocks 3.3.0 and install 3.2.0 for now. It will pick up 3.3.1 as soon as the fix is released.

tiran added a commit to tiran/python-ldap that referenced this issue Jun 29, 2020
macOS system libldap 2.4.28 does not have ldap_init_fd symbol. Disable
initialize_fd when Apple libldap 2.4.28 is detected.

Also run some macOS tests on Travis CI. Since the SDK does not ship
slapd, testing is rather limited.

Fixes: python-ldap#359
Signed-off-by: Christian Heimes <cheimes@redhat.com>
tiran added a commit to tiran/python-ldap that referenced this issue Jun 29, 2020
macOS system libldap 2.4.28 does not have ldap_init_fd symbol. Disable
initialize_fd when Apple libldap 2.4.28 is detected.

Also run some macOS tests on Travis CI. Since the SDK does not ship
slapd, testing is rather limited.

Fixes: python-ldap#359
Signed-off-by: Christian Heimes <cheimes@redhat.com>
tiran added a commit to tiran/python-ldap that referenced this issue Jun 29, 2020
macOS system libldap 2.4.28 does not have ldap_init_fd symbol. Disable
initialize_fd when Apple libldap 2.4.28 is detected.

Also run some macOS tests on Travis CI. Since the SDK does not ship
slapd, testing is rather limited.

Fixes: python-ldap#359
Signed-off-by: Christian Heimes <cheimes@redhat.com>
encukou pushed a commit that referenced this issue Jun 29, 2020
Fix macOS SDK builds without ldap_init_fd

macOS system libldap 2.4.28 does not have ldap_init_fd symbol. Disable
initialize_fd when Apple libldap 2.4.28 is detected.

Also run some macOS tests on Travis CI. Since the SDK does not ship
slapd, testing is rather limited.

#360
Fixes: #359
Signed-off-by: Christian Heimes <cheimes@redhat.com>
@encukou
Copy link
Member

encukou commented Jun 29, 2020

This should be fixed in the fresh python-ldap 3.3.1.
Thank you for your patience!

@mvreijn
Copy link

mvreijn commented Oct 31, 2021

Even though this should be fixed, I run into the same error on my MBP with Big Sur and homebrew LDAP libs (2.5.8):

Traceback (most recent call last):
  File "/...path.../18-gcvs-conversion.py", line 8, in <module>
    import ldap,ldif
  File "/usr/local/lib/python3.9/site-packages/ldap/__init__.py", line 34, in <module>
    import _ldap
ImportError: dlopen(/usr/local/lib/python3.9/site-packages/_ldap.cpython-39-darwin.so, 2): Symbol not found: _ldap_init_fd
  Referenced from: /usr/local/lib/python3.9/site-packages/_ldap.cpython-39-darwin.so
  Expected in: flat namespace
 in /usr/local/lib/python3.9/site-packages/_ldap.cpython-39-darwin.so

@jaycuse
Copy link

jaycuse commented Apr 28, 2022

This is still an issue for MBP Monterey 12.3.1 (21E258)

Tried with both python-ldap version 3.4.0 and 3.3.1
openldap version 2.6.1
python version 3.9.12

    import _ldap
ImportError: dlopen(/path/to/virtualenvs/myvenv/lib/python3.9/site-packages/_ldap.cpython-39-darwin.so, 0x0002): symbol not found in flat namespace '_ldap_init_fd'

python-ldap was installed using

LDFLAGS="-L/usr/local/opt/openldap/lib" CPPFLAGS="-I/usr/local/opt/openldap/include" pip install python-ldap --global-option=build_ext --global-option="-I$(xcrun --show-sdk-path)/usr/include/sasl"

@mistotebe
Copy link
Contributor

Are you sure you're linking against your own libldap? To me it looks like you're still linking against the system version at runtime (no rpath). You should be able to use ldd on the .so file to check this.

@jaycuse
Copy link

jaycuse commented Apr 28, 2022

I think that's why I include LDFLAGS and CPPFLAGS when running pip install.
if I do brew info openldap
Part of it's output is

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

When I don't include these while installing python-ldap. After it's installed and I try to use python-ldap, I get an error about ldap.OPT_X_TLS_CACERTFILE throwing ValueError: option error when I try to set it.

However, I could be misunderstanding something.
ldd isn't on macos, but using otool -L it prints shared libraries being used.

> otool -L /path/to/virtualenvs/myvenv//lib/python3.9/site-packages/_ldap.cpython-39-darwin.so
/path/to/virtualenvs/myvenv/lib/python3.9/site-packages/_ldap.cpython-39-darwin.so:
	/System/Library/Frameworks/LDAP.framework/Versions/A/LDAP (compatibility version 1.0.0, current version 2.4.0)
	/usr/local/opt/openldap/lib/liblber.2.dylib (compatibility version 3.0.0, current version 3.200.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.100.3)

Edit:
I'm thinking you're right. My openldap gets added but because that system library shows up before openldap, it's the first to get used. I don't know enough about ld to know how to try and tell it to exclude specific system libraries or search dirs. Based on what I'm reading in the manpages I'm not even sure I can do that. Thanks for the feed back, I guess this isn't the same issue and more a building issue. I'll look into building it manually rather than using pip.

@henriquebonadio
Copy link

I'll look into building it manually rather than using pip.

Any luck on that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants