I can't install python-ldap

PythonModuleLdap

Python Problem Overview


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

Any ideas how to fix this?

Python Solutions


Solution 1 - Python

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 libldap2-dev libssl-dev

RedHat/CentOS:

sudo yum install python-devel openldap-devel

Solution 2 - Python

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

Solution 3 - Python

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

Solution 4 - Python

In Ubuntu it looks like this :

 $ sudo apt-get install python-dev libldap2-dev libsasl2-dev libssl-dev
 $ sudo pip install python-ldap

Solution 5 - Python

"Don't blindly remove/install software"

In a Ubuntu/Debian based distro, you could 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
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

Solution 6 - Python

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 32bit install at that)

easy_install python-ldap

Solution 7 - Python

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

Available from version 3.3 up to Edge

Available for both armhf and x86_64 Architectures.

Solution 8 - Python

On Fedora 22, you need to do this instead:

sudo dnf install python-devel
sudo dnf install openldap-devel

Solution 9 - Python

For alpine docker

apk add openldap-dev

if the python version is 3 and above try

pip install python3-ldap

Solution 10 - Python

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

Solution 11 - Python

python3 does not support python-ldap. Rather to install ldap3.

Solution 12 - Python

sudo apt-get install build-essential python3-dev python2.7-dev libldap2-dev libsasl2-dev slapd ldap-utils python-tox lcov valgrind

Solution 13 - Python

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 or/and python-ldap 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
EDIT

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)

Solution 14 - Python

On OSX, you need the xcode CLI tools. Just open a terminal and run:

xcode-select --install

Solution 15 - Python

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.)

Solution 16 - Python

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

download the whl file

http://www.lfd.uci.edu/~gohlke/pythonlibs/#python-ldap.

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

Solution 17 - Python

For ArchLinux/Manjaro for me helped the following command:

yay libldap24

Solution 18 - Python

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 http://packages.ubuntu.com/">name of your Python package on Ubuntu versus PyPI. In this case they're the same.

Obviously doesn't work if the Python package is not in the Ubuntu repos.

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

Solution 19 - Python

In FreeBSD 11:

pkg install openldap-client # for lber.h
pkg install cyrus-sasl # if you need sasl.h
pip install python-ldap

Solution 20 - Python

If you're working with windows machines, you can find 'python-ldap' wheel in this Link and then you can install it

Solution 21 - Python

for those who are using alphine linux, apk add openldap-dev

Solution 22 - Python

try:

ARCHFLAGS="-arch x86_64" pip3 install python-ldap

Solution 23 - Python

Adding also libzbar-dev solved for me the installation of python-ldap when building DOCKER

The full command becomes:

apt-get install -y python-dev libldap2-dev libsasl2-dev libssl-dev libzbar-dev

Solution 24 - Python

As of december 2021 there was/is a strange problem with the ldap library (at least in arch/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 here: https://github.com/python-ldap/python-ldap/issues/432#issuecomment-974799221

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 >

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionVacuumTubeView Question on Stackoverflow
Solution 1 - PythonAndiDogView Answer on Stackoverflow
Solution 2 - PythonjmuView Answer on Stackoverflow
Solution 3 - PythonBanjerView Answer on Stackoverflow
Solution 4 - PythonJeff SheffieldView Answer on Stackoverflow
Solution 5 - PythonGayan WeerakuttiView Answer on Stackoverflow
Solution 6 - Pythonarchangel76View Answer on Stackoverflow
Solution 7 - PythonIlhicasView Answer on Stackoverflow
Solution 8 - PythonchfwView Answer on Stackoverflow
Solution 9 - PythonAkhilraj N SView Answer on Stackoverflow
Solution 10 - PythonChristian BerendtView Answer on Stackoverflow
Solution 11 - PythonAgnel AmodiaView Answer on Stackoverflow
Solution 12 - PythonThomas JohnView Answer on Stackoverflow
Solution 13 - PythonMilovan TomaševićView Answer on Stackoverflow
Solution 14 - PythonAndy FraleyView Answer on Stackoverflow
Solution 15 - PythonPetr ViktorinView Answer on Stackoverflow
Solution 16 - PythonTono KuriakoseView Answer on Stackoverflow
Solution 17 - PythonzifterView Answer on Stackoverflow
Solution 18 - PythonlofidevopsView Answer on Stackoverflow
Solution 19 - Pythonxsc27View Answer on Stackoverflow
Solution 20 - PythonpietàView Answer on Stackoverflow
Solution 21 - PythonVivin VeeraliView Answer on Stackoverflow
Solution 22 - Pythonzain mukatiView Answer on Stackoverflow
Solution 23 - PythonMarco CerlianiView Answer on Stackoverflow
Solution 24 - PythonMacMartinView Answer on Stackoverflow