执行以下命令时:

sudo pip install python-ldap

我得到这个错误:

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

有什么解决办法吗?


当前回答

对FreeBSD 13.1的一个hack答案(是的,我知道这是最佳实践的深层南方,但我只是需要一个快速修复):

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

其他回答

在CentOS/RHEL 6上,您需要安装:

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

yum还将安装cyrus- sass -devel作为依赖项。然后你可以运行:

pip-2.7 install python-ldap

在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时,我学会了这个技巧。

在OSX上,你需要xcode命令行工具。只需打开一个终端并运行:

xcode-select --install

Windows:我完全同意这个公认的答案,但我花了一段时间才从评论中找到我想要的东西。我使用Bitnami在Windows上的Reviewboard遇到了这个特定的问题。为了给出windows的答案,我使用了评论中提到的这个链接:

http://www.lfd.uci.edu/~gohlke/pythonlibs/#python-ldap 将该车轮(whl文件)放入我的审查板安装目录

然后执行如下命令

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

(因为我安装了python 2.7和32位)

easy_install python-ldap

在openSUSE上需要安装openldap2-devel、cyrus-sasl-devel、python-devel和libopenssl-devel。

Zypper安装openldap2-devel cyrus-sasl-devel python-devel libopenssl-devel