简体   繁体   English

在Redhat Enterprise Server上安装python-ldap时解决GCC错误

[英]Resolve GCC error when installing python-ldap on Redhat Enterprise Server

Python-LDAP + Redhat = Gnashing of Teeth Python-LDAP + Redhat =咬牙切齿

Recently, I spent a few hours tearing my hair (or what's left of it) out attempting to install python-ldap (via pip) onto a Redhat Enterprise server. 最近,我花了几个小时撕掉我的头发(或者剩下的东西)试图将python-ldap(通过pip)安装到Redhat Enterprise服务器上。

Here's the error message that I would get (look familiar?): 这是我会得到的错误消息(看起来很熟悉?):

Modules/constants.c:365: error: 'LDAP_CONTROL_RELAX' undeclared (first use in this function) error: command 'gcc' failed with exit status 1

If only there was someone out there that could help me! 如果只有那里有人可以帮助我!

But wait! 可是等等! I can help you, because I figured it out after a copious amount of cursing! 我可以帮助你,因为我经过大量的诅咒后想出来了!

Step 1: Verify Prerequisites are Installed 步骤1:验证是否已安装先决条件

According to the docs you must have OpenLDAP libraries installed on your system. 根据文档,您必须在系统上安装OpenLDAP库。 At the time that I'm writing the version requirement for the libraries was >= 2.4.11 在我写这些库的版本要求时> = 2.4.11

To see whether or not you have such libraries installed on your system, run this command: yum list installed openldap* 要查看您的系统上是否安装了此类库,请运行以下命令: yum list installed openldap*

Here is the output from my system as an example of what you might see: 以下是我系统的输出,作为您可能会看到的示例:

PACKAGE                                                         VERSION
openldap24-libs.i386                                            2.4.23-5.el5                                     
openldap24-libs.x86_64                                          2.4.23-5.el5                                     
openldap24-libs-devel.i386                                      2.4.23-5.el5                                     
openldap24-libs-devel.x86_64                                    2.4.23-5.el5

So, in my case, I already had the libraries installed. 所以,就我而言,我已经安装了库。 If you don't just run: 如果你不只是运行:

sudo yum install openldap24-libs-devel  
sudo yum install openldap24-libs

Step 2: Where were those Packages Installed? 第2步:这些软件包安装在哪里?

If the packages are already installed and pip is still failing, then perhaps the setup.cfg script is looking in the wrong place for the required library files. 如果软件包已经安装且pip仍然失败,那么setup.cfg脚本可能在错误的位置查找所需的库文件。 So, let's find out where they exist on our system. 那么,让我们找出它们在我们系统中的位置。

Do this: 做这个:

rpm -ql openldap24-libs
rpm -ql openldap24-libs-devel

And you should get something like this (I've abbreviated this so we can see the directories involved more easily). 你应该得到这样的东西(我已经缩写了这个,所以我们可以更容易地看到涉及的目录)。

rpm -ql openldap24-libs
/usr/lib64/...
/usr/lib/...

rpm -ql openldap24-libs-devel
/usr/include/openldap24/...
/usr/lib/openldap24/...
/usr/lib64/openldap24/...

Step 3: Check Pip's setup.cfg file for python-ldap 第3步:检查Pip的setup.cfg文件中的python-ldap

  • When a pip install command fails, it leaves behind a build directory inside of the python interpreter's base directory (same place that you'll find /bin, /include, /lib, and /man. 当pip install命令失败时,它会在python解释器的基目录中留下一个build目录(你会找到/ bin,/ include,/ lib和/ man的相同位置)。
  • Inside the build directory you should find `python-ldap/setup.cfg'. build目录中,你应该找到`python-ldap / setup.cfg'。
  • Open the file inside your favorite editor. 在您喜欢的编辑器中打开文件。

You should see this at the top of the file: 你应该在文件的顶部看到这个:

[_ldap]
library_dirs = /opt/openldap-RE24/lib /usr/lib
include_dirs = /opt/openldap-RE24/include /usr/include/sasl /usr/include

Obviously, this is wrong. 显然,这是错误的。 Append the directories you discovered in step 2 in front of the directories currently listed so that you end up with something like: 将您在步骤2 发现的目录附加到当前列出的目录前面 ,以便最终得到如下内容:

[_ldap]
library_dirs = /usr/lib64/openldap24 /usr/lib/openldap24 /usr/lib64 /opt/openldap-RE24/lib /usr/lib
include_dirs = /usr/include/openldap24 /opt/openldap-RE24/include /usr/include/sasl /usr/include

Step 4: Re-Run Installation & PROFIT! 第4步:重新运行安装和利润!

After saving the file, you can simply run pip install python-ldap again. 保存文件后,您只需再次运行pip install python-ldap The installation process will look at your update setup.cfg and should install without any further issues. 安装过程将查看您的更新setup.cfg,并且应该安装而不会出现任何进一步的问题。

An alternative to step 3 in eikonomega's answer : eikonomega答案中第3步的替代方案:

$ export CPATH=/usr/include/openldap24/
$ export LIBRARY_PATH=/usr/lib64/openldap24/

then: 然后:

$ pip install python-ldap

No having to crack-open the setup.cfg! 无需破解setup.cfg!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM