我无法安装python-ldap

问题:我无法安装python-ldap

当我运行以下命令时:

sudo pip install python-ldap

我收到此错误:

在Modules / LDAPObject.c:9包含的文件中:

Modules / errors.h:8:致命错误:lber.h:没有此类文件或目录

任何想法如何解决这一问题?

When I run the following command:

sudo pip install python-ldap

I get this error:

In file included from Modules/LDAPObject.c:9:

Modules/errors.h:8: fatal error: lber.h: No such file or directory

Any ideas how to fix this?


回答 0

Python,LDAP是基于OpenLDAP的,所以你必须为了编译Python模块的开发文件(头)。如果您使用的是Ubuntu,则该软件包称为libldap2-dev

Debian / Ubuntu

sudo apt-get install libsasl2-dev python-dev libldap2-dev libssl-dev

RedHat / CentOS

sudo yum install python-devel openldap-devel

The python-ldap is based on OpenLDAP, so you need to have the development files (headers) in order to compile the Python module. If you’re on Ubuntu, the package is called libldap2-dev.

Debian/Ubuntu:

sudo apt-get install libsasl2-dev python-dev libldap2-dev libssl-dev

RedHat/CentOS:

sudo yum install python-devel openldap-devel

回答 1

要使用pip成功安装python-ldap,需要以下开发库(软件包名称取自ubuntu环境):

sudo apt-get install -y python-dev libldap2-dev libsasl2-dev libssl-dev

To install python-ldap successfully with pip, following development libraries are needed (package names taken from ubuntu environment):

sudo apt-get install -y python-dev libldap2-dev libsasl2-dev libssl-dev

回答 2

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

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

yum也将cyrus-sasl-devel作为依赖项安装。然后,您可以运行:

pip-2.7 install python-ldap

On CentOS/RHEL 6, you need to install:

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

and yum will also install cyrus-sasl-devel as a dependency. Then you can run:

pip-2.7 install python-ldap

回答 3

在Ubuntu中,它看起来像这样:

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

In Ubuntu it looks like this :

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

回答 4

Windows:我完全同意接受的答案,但是仔细阅读评论需要花一些时间才能弄清我需要的内容。我使用Bitnami在Windows上的Reviewboard上遇到了这个特定问题。为了给出Windows的答案,我使用了注释中提到的以下链接:

然后,执行以下命令

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

(因为我当时安装了python 2.7和32位安装程序)

easy_install python-ldap

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. I ran across this specific problem with Reviewboard on Windows using the Bitnami. To give an answer for windows then, I used this link mentioned in the comments:

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)

easy_install python-ldap

回答 5

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

在基于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-file search lber.h,您只需要安装软件包libldap2-dev

sudo apt-get install libldap2-dev

“Don’t blindly remove/install software”

In a Ubuntu/Debian based distro, you could use apt-file to find the name of the exact package that includes the missing header 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.

sudo apt-get install libldap2-dev

回答 6

对于那些在Alpine Linux上也缺少Iber.h的问题,例如,您尝试在Docker映像中尝试适应Alpine。

您要查找的软件包是:openldap-dev

所以跑

apk add openldap-dev

从版本3.3到Edge可用

适用于armhf和x86_64体系结构。

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.

The package you are looking for is: openldap-dev

So run

apk add openldap-dev

Available from version 3.3 up to Edge

Available for both armhf and x86_64 Architectures.


回答 7

在openSUSE需要安装的软件包openldap2-develcyrus-sasl-develpython-devellibopenssl-devel

zypper install openldap2-devel cyrus-sasl-devel python-devel libopenssl-devel

On openSUSE you need to install the packages openldap2-devel, cyrus-sasl-devel, python-devel and libopenssl-devel.

zypper install openldap2-devel cyrus-sasl-devel python-devel libopenssl-devel


回答 8

在Fedora 22上,您需要执行以下操作:

sudo dnf install python-devel
sudo dnf install openldap-devel

On Fedora 22, you need to do this instead:

sudo dnf install python-devel
sudo dnf install openldap-devel

回答 9

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

xcode-select --install

On OSX, you need the xcode CLI tools. Just open a terminal and run:

xcode-select --install

回答 10

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

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

For most systems, the build requirements are now mentioned in python-ldap’s documentation, in the “Installing” section.

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.)


回答 11

python3不支持python-ldap。而是安装ldap3。

python3 does not support python-ldap. Rather to install ldap3.


回答 12

要更正由于依赖而导致的错误,请安装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

To correct the error due to dependencies to install the python-ldap : Windows 7/10

download the whl file

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

python 3.6 suit with

python_ldap-3.2.0-cp36-cp36m-win_amd64.whl

Deploy the file in :

c:\python36\Scripts\

install it with

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

回答 13

在FreeBSD 11中:

pkg install openldap-client # for lber.h
pkg install cyrus-sasl # if you need sasl.h
pip install python-ldap

In FreeBSD 11:

pkg install openldap-client # for lber.h
pkg install cyrus-sasl # if you need sasl.h
pip install python-ldap

回答 14

作为在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和PyPI 检查Python软件包名称。在这种情况下,它们是相同的。

如果Python软件包不在Ubuntu仓库中,显然不起作用。

[1]我尝试pip install matplotlib在Ubuntu上学习了这个技巧。

As a general solution to install Python packages with binary dependencies [1] on Debian/Ubuntu:

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. In this case they’re the same.

Obviously doesn’t work if the Python package is not in the Ubuntu repos.

[1] I learnt this trick when trying to pip install matplotlib on Ubuntu.


回答 15

对于高山码头工人

apk add openldap-dev

如果python版本是3以上,请尝试

pip install python3-ldap

For alpine docker

apk add openldap-dev

if the python version is 3 and above try

pip install python3-ldap

回答 16

如果您使用的是Windows计算机,则可以在此链接中找到“ python-ldap”轮,然后进行安装

If you’re working with windows machines, you can find ‘python-ldap’ wheel in this Link and then you can install it


回答 17

对于使用alphine linux的用户,apk添加openldap-dev

for those who are using alphine linux, apk add openldap-dev


回答 18

sudo apt-get install build-essential python3-dev python2.7-dev libldap2-dev libsasl2-dev slapd ldap-utils python-tox lcov valgrind
sudo apt-get install build-essential python3-dev python2.7-dev libldap2-dev libsasl2-dev slapd ldap-utils python-tox lcov valgrind