执行以下命令时:

sudo pip install python-ldap

我得到这个错误:

在Modules/LDAPObject.c:9包含的文件中: Modules/errors.h:8:致命错误:lber.h:没有这样的文件或目录

有什么解决办法吗?


当前回答

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

Debian参考: https://www.python-ldap.org/en/latest/installing.html#debian 其他信息:https://www.python-ldap.org/en/latest/installing.html

其他回答

在Fedora 22上,您需要这样做:

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

“不要盲目地删除/安装软件”

在基于Ubuntu或Debian的发行版中,您可以使用apt-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

正如您可以从apt文件搜索lber.h的输出中看到的,您只需要安装包libldap2-dev。

sudo apt-get install libldap2-dev

在Debian/Ubuntu上安装二进制依赖的Python包[1]的通用解决方案:

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

你必须在Ubuntu和PyPI上检查你的Python包的名称。在这种情况下,它们是一样的。

显然,如果Python包不在Ubuntu回购中,则无法工作。

当我尝试在Ubuntu上安装matplotlib时,我学会了这个技巧。

在FreeBSD 11中:

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

我在Windows上的安装遇到了问题,因此解决方案之一是手动安装ldap包。

以下几个步骤:

进入“pyldap”或“/and python-ldap”页面,下载最新版本“*whl”。 打开一个控制台,然后cd到你下载文件的地方。WHL和用途:

pip install some-package.whl

pyldap的当前版本是2.4.45。在一个具体的例子中,安装将是:

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

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

输出:

Installing collected packages: pyldap
Successfully installed pyldap-2.4.45

EDIT

您可以为Python-3安装合适的版本。使用以下命令:

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

# otherwise 
pip install python3-ldap

这里还有PiPy包的链接以获取更多信息:python3-ldap 0.9.8.4

OR

ldap3是一个严格符合RFC 4510的LDAP V3纯Python客户端库。同样的代码库在Python 2、Python 3、PyPy和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)