我无法安装Python-LDAP

349
当我运行以下命令时:
sudo pip install python-ldap

我遇到了这个错误:
在文件Modules/LDAPObject.c中包含的时候:
Modules/errors.h:8: 致命错误:lber.h:没有那个文件或目录
我该如何修复这个问题?
27个回答

4

针对alpine docker

apk add openldap-dev

如果Python版本是3及以上,请尝试:

pip install python3-ldap

4
在 openSUSE 上,您需要安装以下软件包:openldap2-develcyrus-sasl-develpython-devellibopenssl-devel
使用以下命令安装:zypper install openldap2-devel cyrus-sasl-devel python-devel libopenssl-devel

4

Python 3不支持python-ldap。请安装ldap3


3

对于大多数系统,构建要求现在在python-ldap的文档中提到,在“安装”部分。

如果您的系统缺少任何内容(或者您的系统完全丢失),请告诉维护者! (截至2018年,我是维护者,因此在此处发表评论应该就足够了。或者您可以发送拉取请求或邮件。)


谢谢,值得注意的是,如果你在运行Python3,你需要安装python3-devel而不是python-devel。 - Jamie

3
截至2021年12月,在ldap库(至少在arch/manjaro中)存在一个奇怪的问题。
在安装python-ldap时(在“为python-ldap构建轮子”处),我收到了“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  

这里提供了一种解决方法:https://github.com/python-ldap/python-ldap/issues/432#issuecomment-974799221 我引用如下:

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

Manjaro用户确认 :D - sweisgerber.dev

3

1
为什么要安装 Valgrind? - BlakBat
最好咨询维护者们的意见,这是他们的建议。来源 - Seth Falco

2
在OSX上,您需要xcode CLI工具。只需打开终端并运行:
xcode-select --install

2

对于ArchLinux/Manjaro,以下命令对我有帮助:

yay libldap24

1
它在Manjaro上运行成功了,谢谢。 - Konrados

1
在FreeBSD 11中:
pkg install openldap-client # for lber.h
pkg install cyrus-sasl # if you need sasl.h
pip install python-ldap

1
作为在Debian/Ubuntu上安装具有二进制依赖项[1]的Python包的通用解决方案:
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上的Python包名称与PyPI上的是否相同。如果不在Ubuntu存储库中,则无法使用此方法。
[1] 当我在Ubuntu上尝试安装matplotlib时,学到了这个技巧。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接