[英]I can't install python-ldap
When I run the following command:当我运行以下命令时:
sudo pip install python-ldap
I get this error:我收到此错误:
In file included from Modules/LDAPObject.c:9:
在 Modules/LDAPObject.c:9 中包含的文件中:
Modules/errors.h:8: fatal error: lber.h: No such file or directory
Modules/errors.h:8: 致命错误: lber.h: 没有这样的文件或目录
Any ideas how to fix this?任何想法如何解决这一问题?
The python-ldap is based on OpenLDAP, so you need to have the development files (headers) in order to compile the Python module. python-ldap基于 OpenLDAP,因此您需要拥有开发文件(头文件)才能编译 Python 模块。 If you're on Ubuntu, the package is called
libldap2-dev
.如果您使用的是 Ubuntu,则该软件包称为
libldap2-dev
。
Debian/Ubuntu : Debian/Ubuntu :
sudo apt-get install libsasl2-dev python-dev libldap2-dev libssl-dev
RedHat/CentOS :红帽/CentOS :
sudo yum install python-devel openldap-devel
要使用 pip 成功安装 python-ldap,需要以下开发库(包名取自 ubuntu 环境):
sudo apt-get install -y python-dev libldap2-dev libsasl2-dev libssl-dev
On CentOS/RHEL 6, you need to install:在 CentOS/RHEL 6 上,您需要安装:
sudo yum install python-devel
sudo yum install openldap-devel
and yum will also install cyrus-sasl-devel
as a dependency.并且 yum 还将安装
cyrus-sasl-devel
作为依赖项。 Then you can run:然后你可以运行:
pip-2.7 install python-ldap
In Ubuntu it looks like this :在 Ubuntu 中,它看起来像这样:
$ sudo apt-get install python-dev libldap2-dev libsasl2-dev libssl-dev
$ sudo pip install python-ldap
In a Ubuntu or Debian based distro, you can use apt-file
to find the name of the exact package that includes the missing header file.在基于 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
As you could see from the output of apt-file search lber.h
, you'd just need to install the package libldap2-dev
.从
apt-file search lber.h
的输出中可以看出,您只需要安装软件包libldap2-dev
。
sudo apt-get install libldap2-dev
Windows: I completely agree with the accepted answer, but digging through the comments took a while to get to the meat of what I needed. Windows:我完全同意接受的答案,但仔细研究评论需要一段时间才能找到我需要的内容。 I ran across this specific problem with Reviewboard on Windows using the Bitnami.
我使用 Bitnami 在 Windows 上的 Reviewboard 上遇到了这个特定问题。 To give an answer for windows then, I used this link mentioned in the comments:
为了给 Windows 一个答案,我使用了评论中提到的这个链接:
Then, executed the following commands然后,执行以下命令
easy_install pip
pip install python_ldap-2.4.20-cp27-none_win32.whl
(because I had python 2.7 and a 32bit install at that) (因为我安装了 python 2.7 和 32 位)
easy_install python-ldap
For those having the same issue of missing Iber.h on Alpine Linux, in a docker image that you are trying to adapt to Alpine for instance.对于那些在 Alpine Linux 上缺少 Iber.h 的相同问题的人,例如,在您尝试适应 Alpine 的 docker 映像中。
The package you are looking for is: openldap-dev你要找的包是:openldap-dev
So run所以运行
apk add openldap-dev
Available from version 3.3 up to Edge从 3.3 版到 Edge 可用
Available for both armhf and x86_64 Architectures.可用于 armhf 和 x86_64 架构。
On Fedora 22, you need to do this instead:在 Fedora 22 上,您需要这样做:
sudo dnf install python-devel
sudo dnf install openldap-devel
在 openSUSE 上,您需要安装软件包openldap2-devel
、 cyrus-sasl-devel
、 python-devel
和libopenssl-devel
。
zypper install openldap2-devel cyrus-sasl-devel python-devel libopenssl-devel
For alpine docker对于高山码头
apk add openldap-dev
if the python version is 3 and above try如果python版本是3及以上试试
pip install python3-ldap
For most systems , the build requirements are now mentioned in python-ldap's documentation , in the "Installing" section.对于大多数系统,构建要求现在在python-ldap 的文档中的“安装”部分中提到。
If anything is missing for your system (or your system is missing entirely), please let maintainer know!如果您的系统缺少任何东西(或您的系统完全丢失),请让维护人员知道! (As of 2018, I am the maintainer, so a comment here should be enough. Or you can send a pull request or mail.)
(截至 2018 年,我是维护者,所以在这里发表评论就足够了。或者您可以发送拉取请求或邮件。)
python3 does not support python-ldap. python3 不支持 python-ldap。 Rather to install ldap3.
而是安装ldap3。
To correct the error due to dependencies to install the python-ldap : Windows 7/10纠正由于依赖关系而导致的错误以安装 python-ldap:Windows 7/10
download the whl file下载whl文件
http://www.lfd.uci.edu/~gohlke/pythonlibs/#python-ldap . http://www.lfd.uci.edu/~gohlke/pythonlibs/#python-ldap 。
python 3.6 suit with python 3.6套装与
python_ldap-3.2.0-cp36-cp36m-win_amd64.whl
Deploy the file in :将文件部署在:
c:\python36\Scripts\
c:\python36\脚本\
install it with安装它
python -m pip install python_ldap-3.2.0-cp36-cp36m-win_amd64.whl
sudo apt-get install build-essential python3-dev python2.7-dev libldap2-dev libsasl2-dev slapd ldap-utils python-tox lcov valgrind
I had problems with the installation on Windows, so one of the solutions is to install the ldap
package manually.我在 Windows 上安装时遇到问题,因此解决方案之一是手动安装
ldap
包。
A few steps:几个步骤:
*whl
.*whl
。some-package.whl
and use:some-package.whl
并使用:pip install some-package.whl
The current version for pyldap
is 2.4.45
. 2.4.45
pyldap
On a concrete example the installation would be:在一个具体的例子中,安装将是:
pip install .\pyldap-2.4.45-cp37-cp37m-win_amd64.whl
# or
pip install .\python_ldap‑3.3.1‑cp39‑cp39‑win_amd64.whl
Output:输出:
Installing collected packages: pyldap
Successfully installed pyldap-2.4.45
You can install the proper version for Python-3.X though using following command:您可以使用以下命令为 Python-3.X 安装正确的版本:
# if pip3 is the default pip alias for python-3
pip3 install python3-ldap
# otherwise
pip install python3-ldap
Also here is the link of PiPy package for further information: python3-ldap 0.9.8.4另外这里是 PiPy 包的链接以获取更多信息: python3-ldap 0.9.8.4
ldap3 is a strictly RFC 4510 conforming LDAP V3 pure Python client library. ldap3 是一个严格遵循 RFC 4510 的 LDAP V3 纯 Python 客户端库。 The same codebase runs in Python 2, Python 3, PyPy and PyPy3: https://github.com/cannatag/ldap3
相同的代码库在 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)
On OSX, you need the xcode CLI tools.在 OSX 上,您需要 xcode CLI 工具。 Just open a terminal and run:
只需打开一个终端并运行:
xcode-select --install
对于我来说 ArchLinux/Manjaro 帮助了以下命令:
yay libldap24
As a general solution to install Python packages with binary dependencies [1] on Debian/Ubuntu:作为在 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
You'll have to check the name of your Python package on Ubuntu versus PyPI.您必须在 Ubuntu 和 PyPI 上检查 Python 包的名称。 In this case they're the same.
在这种情况下,它们是相同的。
Obviously doesn't work if the Python package is not in the Ubuntu repos.如果 Python 包不在 Ubuntu 存储库中,显然不起作用。
[1] I learnt this trick when trying to pip install matplotlib
on Ubuntu. [1] 我在 Ubuntu 上尝试
pip install matplotlib
时学到了这个技巧。
In FreeBSD 11:在 FreeBSD 11 中:
pkg install openldap-client # for lber.h
pkg install cyrus-sasl # if you need sasl.h
pip install python-ldap
如果您使用的是 windows 机器,您可以在此链接中找到“python-ldap”轮,然后您可以安装它
对于那些使用 alphine linux 的人,apk 添加 openldap-dev
尝试:
ARCHFLAGS="-arch x86_64" pip3 install python-ldap
Adding also libzbar-dev
solved for me the installation of python-ldap
when building DOCKER还添加
libzbar-dev
为我解决了构建DOCKER时安装python-ldap
的问题
The full command becomes:完整的命令变为:
apt-get install -y python-dev libldap2-dev libsasl2-dev libssl-dev libzbar-dev
As of december 2021 there was/is a strange problem with the ldap library (at least in arch/manjaro).截至 2021 年 12 月,ldap 库存在一个奇怪的问题(至少在 arch/manjaro 中)。
While installing python-ldap
(at 'Building wheel for python-ldap') I got the message 'ERROR: Failed building wheel for python-ldap':在安装
python-ldap
时(在“python-ldap 的构建轮”)我收到消息“错误: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
a workaround is provided here: https://github.com/python-ldap/python-ldap/issues/432#issuecomment-974799221此处提供了一种解决方法: https ://github.com/python-ldap/python-ldap/issues/432#issuecomment-974799221
I cite:我引用:
As a workaround create the file /usr/lib64/libldap_r.so with content INPUT ( libldap.so ).
作为一种解决方法,使用内容 INPUT (libldap.so) 创建文件 /usr/lib64/libldap_r.so。 The approach works on all systems that use a GNU ld-compatible linker.
该方法适用于所有使用 GNU ld 兼容链接器的系统。
# cat > /usr/lib64/libldap_r.so << EOF INPUT ( libldap.so ) EOF
+1 为zifter<\/a>答案<\/a>(适用于 Arch Linux \/ Manjaro Linux 用户):
yay libldap24
A hack answer for FreeBSD 13.1 (yes, I know this is deep South of best practices, but I just needed a quick fix): 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.