I can't install python-ldap
Asked Answered
B

27

352

When I run the following command:

sudo pip install python-ldap

I get this error:

In file included from Modules/LDAPObject.c:9:

Modules/errors.h:8: fatal error: lber.h: No such file or directory

How can I fix this?

Bazemore answered 22/1, 2011 at 14:44 Comment(0)
G
630

The python-ldap is based on OpenLDAP, so you need to have the development files (headers) in order to compile the Python module. If you're on Ubuntu, the package is called libldap2-dev.

Debian/Ubuntu:

sudo apt-get install libsasl2-dev python-dev-is-python3 libldap2-dev libssl-dev

Red Hat/CentOS:

sudo yum install python-devel openldap-devel
Gumbotil answered 22/1, 2011 at 14:49 Comment(17)
Thanks for that. It's got further it's now failing with sasl.h no such file or directoryBazemore
@VacuumTube: Missing headers are almost always a sign for missing -dev packages (sometimes also named -devel). Just do apt-cache search sasl | grep dev and you'll probably find the right package - I would guess it's libsasl2-dev.Gumbotil
Anything for windows users :( Same error, no solutions so farDrawshave
You don't have to compile from source on Windows. Just use one of the installers from pypi.python.org/pypi/python-ldap.Herod
Also, Windows users can extract the .msi installer @Herod mentioned to install into a virtualenv: How to install python-ldap on a python 2.7 virtualenv on windows without compiling (see update 2)Bahadur
On Windows you can also use Chris Gohlke's excellent resource for Windows installers: lfd.uci.edu/~gohlke/pythonlibs/#python-ldapBackward
Thanks @AndiDog. the issue was resolved as soon as I installed the -dev library :)Dinkins
Full list should be sudo apt-get install libsasl2-dev python-dev libldap2-dev libssl-devTonedeaf
Notice that you need to run 'sudo apt-get update' first.Astrophysics
Well this is odd. I have installed libldap2-dev but the headers haven't been installed. Everything else in the package (libs, man pages) has. Edit: --reinstall and it's fine.Perturb
@TrinhHoangNhu: Why this that the full list? Can you explain how you found those dependencies?Sizzle
@Sizzle I found out that one since 2015. It may not correct nowTonedeaf
Use python3-dev instead of python-dev if you are using Python 3.Muro
Sometimes also known as python36-devel or python3-devel.x86_64 or python36-devel.x86_64 (aws). When in doubt: yum search python | grep -i devPhosphate
Worth noting in 2022 on Debian 11, I only needed to install libldap2-dev and libsasl2-dev. (Already had python3-virtualenv.)Inconsiderable
for me it didn't find python-dev so I did this: sudo apt-get install libsasl2-dev python-dev-is-python3 libldap2-dev libssl-devAquarelle
I have to remove python-dev parameter to fix the problemEvite
S
158

To install python-ldap successfully with pip, following development libraries are needed (package names taken from ubuntu environment):

sudo apt-get install -y python-dev libldap2-dev libsasl2-dev libssl-dev
Switcheroo answered 4/8, 2011 at 12:42 Comment(0)
S
74

On CentOS/RHEL 6, you need to install:

sudo yum install python-devel
sudo yum install openldap-devel

And YUM will also install cyrus-sasl-devel as a dependency. Then you can run:

pip-2.7 install python-ldap
Seagoing answered 31/10, 2012 at 14:11 Comment(0)
Q
55

"Don't blindly remove/install software"

In a Ubuntu or Debian-based distribution, you can use apt-file to find the name of the exact package that includes the missing header file.

# Do this once
sudo apt-get install apt-file
sudo apt-file update

apt-file search lber.h

Output:

libldap2-dev: /usr/include/lber.h

As you could see from the output of apt-file search lber.h, you'd just need to install the package libldap2-dev.

sudo apt-get install libldap2-dev
Qualification answered 20/1, 2018 at 6:15 Comment(1)
Is there a CentoOS equivalent to this?Barn
C
35

In Ubuntu it looks like this:

sudo apt-get install python-dev libldap2-dev libsasl2-dev libssl-dev
sudo pip install python-ldap
Critical answered 7/12, 2012 at 8:0 Comment(0)
R
17

Windows: I completely agree with the accepted answer, but digging through the comments took a while to get to the meat of what I needed. I ran across this specific problem with Reviewboard on Windows using the Bitnami. To give an answer for Windows then, I used this link mentioned in the comments:

Then, executed the following commands

easy_install pip
pip install python_ldap-2.4.20-cp27-none_win32.whl

(because I had Python 2.7 and a 32-bit install at that)

easy_install python-ldap
Razo answered 13/8, 2015 at 21:24 Comment(1)
#15070563Bohannan
Q
14

For those having the same issue of missing Iber.h on Alpine Linux, in a Docker image that you are trying to adapt to Alpine for instance.

The package you are looking for is: openldap-dev

So run

apk add openldap-dev

Available from version 3.3 up to Edge.

Available for both armhf and x86_64 Architectures.

Quito answered 17/8, 2017 at 17:49 Comment(1)
Good for alpine-based images. Thanks.Humpback
C
7

I had problems with the installation on Windows, so one of the solutions is to install the ldap package manually.

A few steps:

  • Go to the page pyldap and download the latest version *whl.

  • Open a console then cd to where you've downloaded your file like some-package.whl and use:

    pip install some-package.whl
    

The current version for pyldap is 2.4.45. On a concrete example the installation would be:

pip install .\pyldap-2.4.45-cp37-cp37m-win_amd64.whl

# Or
pip install .\python_ldap‑3.3.1‑cp39‑cp39‑win_amd64.whl

Output:

Installing collected packages: pyldap
Successfully installed pyldap-2.4.45

You can install the proper version for Python-3.X though using following command:

# If pip3 is the default pip alias for python-3
pip3 install python3-ldap

# Otherwise
pip install python3-ldap

Also here is the link of PiPy package for further information: python3-ldap 0.9.8.4

OR

ldap3 is a strictly RFC 4510 conforming LDAP V3 pure Python client library. The same codebase runs in Python 2, Python 3, PyPy and PyPy3: https://github.com/cannatag/ldap3

pip install ldap3
from ldap3 import Server, Connection, SAFE_SYNC

server = Server('my_server')
conn = Connection(server, 'my_user', 'my_password', client_strategy=SAFE_SYNC, auto_bind=True)

status, result, response, _ = conn.search('o=test', '(objectclass=*)')
# usually you don't need the original request (4th element of the returned tuple)
Connotative answered 17/9, 2020 at 7:41 Comment(0)
D
6

On Fedora 22, you need to do this instead:

sudo dnf install python-devel
sudo dnf install openldap-devel
Denbrook answered 1/6, 2015 at 14:33 Comment(1)
Still true for F25Streamy
I
4

On openSUSE you need to install the packages openldap2-devel, cyrus-sasl-devel, python-devel and libopenssl-devel.

zypper install openldap2-devel cyrus-sasl-devel python-devel libopenssl-devel

Indic answered 16/7, 2014 at 11:9 Comment(0)
L
4

Python 3 does not support python-ldap. Rather install ldap3.

Losing answered 10/4, 2018 at 17:54 Comment(0)
K
4

For Alpine Docker:

apk add openldap-dev

If the Python version is 3 and above, try

pip install python3-ldap
Kazbek answered 4/6, 2019 at 6:14 Comment(0)
P
4

To correct the error due to dependencies to install the python-ldap: Windows 7 and Windows 10

Download the whl file from:

https://github.com/cgohlke/python-ldap-build (old link http://www.lfd.uci.edu/~gohlke/pythonlibs/#python-ldap no longer working as reported here)

Python 3.6 suit with

python_ldap-3.2.0-cp36-cp36m-win_amd64.whl

Deploy the file in:

C:\python36\Scripts\

Install it with:

python -m pip install python_ldap-3.2.0-cp36-cp36m-win_amd64.whl
Pistil answered 13/11, 2019 at 4:57 Comment(0)
D
3

For most systems, the build requirements are now mentioned in python-ldap's documentation, in the "Installing" section.

If anything is missing for your system (or your system is missing entirely), please let maintainer know! (As of 2018, I am the maintainer, so a comment here should be enough. Or you can send a pull request or mail.)

Dicta answered 13/3, 2018 at 16:2 Comment(1)
Thanks, might be worth noting that if you're running python3, you would need python3-devel, rather than python-devel.Gravy
P
3
sudo apt-get install build-essential python3-dev python2.7-dev libldap2-dev libsasl2-dev slapd ldap-utils python-tox lcov valgrind
Pontifex answered 19/11, 2019 at 13:22 Comment(2)
Why install valgrind?Profitsharing
@Profitsharing Best to ask the maintainers that, it's their recommendation. SourceInconsiderable
P
3

As of December 2021 there was/is a strange problem with the ldap library (at least in Arch Linux/Manjaro).

While installing python-ldap (at 'Building wheel for python-ldap'), I got the message 'ERROR: Failed building wheel for python-ldap':

  /usr/bin/ld: cannot find -lldap_r
  collect2: error: ld returned 1 exit status
  error: command '/usr/bin/gcc' failed with exit code 1

A workaround is provided at Support for OpenLDAP 2.5+ #432.

I cite:

As a workaround create the file /usr/lib64/libldap_r.so with content INPUT ( libldap.so ). The approach works on all systems that use a GNU ld-compatible linker.

# cat > /usr/lib64/libldap_r.so << EOF
INPUT ( libldap.so )
EOF
Phifer answered 13/1, 2022 at 9:52 Comment(1)
Manjaro user confirms :DSharlasharleen
E
2

On OS X, you need the Xcode CLI tools. Just open a terminal and run:

xcode-select --install
Energetic answered 28/6, 2016 at 17:7 Comment(0)
A
2

For Arch Linux/Manjaro, for me, it helped with the following command:

yay libldap24
Aleph answered 13/12, 2021 at 8:32 Comment(1)
It worked on Manjaro, thanksBurdick
B
1

As a general solution to install Python packages with binary dependencies 1 on Debian/Ubuntu:

sudo apt-get build-dep python-ldap
# Installs system dependencies (but not the package itself)
pew workon my_virtualenv # Enter your virtualenv
pip install python-ldap

You'll have to check the name of your Python package on Ubuntu versus PyPI. In this case they're the same.

Obviously, it doesn't work if the Python package is not in the Ubuntu repositories.

[1] I learnt this trick when trying to pip install matplotlib on Ubuntu.

Bohannan answered 6/6, 2016 at 12:59 Comment(0)
G
1

In FreeBSD 11:

pkg install openldap-client # For lber.h
pkg install cyrus-sasl # If you need sasl.h
pip install python-ldap
Garceau answered 26/11, 2016 at 23:45 Comment(0)
C
1

Also adding libzbar-dev during the installation of python-ldap when building Docker solved it for me.

The full command becomes:

apt-get install -y python-dev libldap2-dev libsasl2-dev libssl-dev libzbar-dev
Consonantal answered 2/12, 2021 at 17:19 Comment(0)
S
1

Ubuntu

The package python-dev is deprecated or not longer available. You can use this instead:

sudo apt-get install libsasl2-dev python2-dev python2 python-dev-is-python3 libldap2-dev libssl-dev
pip install python-ldap

---Edit--- trying to install python-dev

Speedway answered 15/7, 2023 at 20:45 Comment(5)
Re "is deprecated": On what version of Ubuntu? And what version of Ubuntu was it tested on? Please respond by editing (changing) your answer, not here in comments (but *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** without *** *** *** *** *** *** *** *** *** *** *** *** *** *** "Edit:", "Update:", or similar - the answer should appear as if it was written today).Pelvic
Why python2-dev and python2? Why are they necessary?Pelvic
From another answer: "Python 3 does not support python-ldap. Rather install ldap3."Pelvic
Please review Why not upload images of code/errors when asking a question? (e.g., "Images should only be used to illustrate problems that can't be made clear in any other way, such as to provide screenshots of a user interface.") (it covers answers as well). And also Edit: or Update: (bad practice on Stack Overflow) (near "Changelogs")Pelvic
To repeat a previous comment: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** without *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** "Edit:", "Update:", or similar - the answer should appear as if it was written today!!!!!!!!!!!!!!!!!!!!! What isn't clear?Pelvic
A
0

If you're working with Windows machines, you can find the 'python-ldap' wheel in this link and then you can install it.

Apocopate answered 28/5, 2018 at 12:9 Comment(0)
M
0

For those who are using Alpine Linux,

apk add openldap-dev
Miquelmiquela answered 1/3, 2019 at 23:2 Comment(0)
I
0

Try:

ARCHFLAGS="-arch x86_64" pip3 install python-ldap
Ignaz answered 28/6, 2021 at 16:37 Comment(2)
Can you please explain what this does?Savagism
Answer needs supporting information Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Gather
K
0

A hack answer for FreeBSD 13.1 (yes, I know this is deep South of best practices, but I just needed a quick fix):

pkg install openldap24-client

cd /usr/local/include/python3.9
ln -s ../<all of the below> .

lber.h
lber_types.h
ldap.h
ldap_cdefs.h
ldap_features.h
ldap_schema.h
ldap_utf8.h
openldap.h
sasl

pip install python-ldap
Kasiekask answered 6/8, 2022 at 15:46 Comment(1)
How is it supposed to work? Why does it work?Pelvic
D
0

You need to install libldap2-dev (sudo apt-get install libldap2-dev), but python-dev is also important. Remember to use the version you have (sudo apt-get install python3.8-dev or sudo apt-get install pythonX.X-dev)

Declamation answered 21/4, 2023 at 6:0 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.