执行以下命令时:

sudo pip install python-ldap

我得到这个错误:

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

有什么解决办法吗?


当前回答

截至2021年12月,ldap库出现了一个奇怪的问题(至少在arch/manjaro中)。

在安装python-ldap(在'Building wheel for 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

我引用:

作为解决方案,创建文件/usr/lib64/libldap_r.关于内容 输入(libldap。)。这种方法适用于所有使用GNU的系统 ld-compatible链接器。 # cat > /usr/lib64/libldap_r.so << EOF 输入(libldap。) EOF

其他回答

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

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

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

pip-2.7 install python-ldap

对于ArchLinux/Manjaro,为我提供了以下命令:

yay libldap24

截至2021年12月,ldap库出现了一个奇怪的问题(至少在arch/manjaro中)。

在安装python-ldap(在'Building wheel for 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

我引用:

作为解决方案,创建文件/usr/lib64/libldap_r.关于内容 输入(libldap。)。这种方法适用于所有使用GNU的系统 ld-compatible链接器。 # cat > /usr/lib64/libldap_r.so << EOF 输入(libldap。) EOF

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

在基于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

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