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.
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!
According to the docs you must have OpenLDAP libraries installed on your system. At the time that I'm writing the version requirement for the libraries was >= 2.4.11
To see whether or not you have such libraries installed on your system, run this command: 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
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. 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/...
build
directory inside of the python interpreter's base directory (same place that you'll find /bin, /include, /lib, and /man.build
directory you should find `python-ldap/setup.cfg'.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:
[_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
After saving the file, you can simply run pip install python-ldap
again. The installation process will look at your update setup.cfg and should install without any further issues.
An alternative to step 3 in eikonomega's answer:
$ export CPATH=/usr/include/openldap24/
$ export LIBRARY_PATH=/usr/lib64/openldap24/
then:
$ pip install python-ldap
No having to crack-open the setup.cfg!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With