执行以下命令时:

sudo pip install python-ldap

我得到这个错误:

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

有什么解决办法吗?


当前回答

修正由于安装python-ldap依赖关系导致的错误:Windows 7/10

下载WHL文件

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

Python 3.6套装

python_ldap-3.2.0-cp36-cp36m-win_amd64.whl

将文件部署到:

c:\python36\Scripts\

使用

python -m pip install python_ldap-3.2.0-cp36-cp36m-win_amd64.whl

其他回答

我在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)

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

对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

截至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中,它是这样的:

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