1

During installation python-ldap using pip (pip install python-ldap) I receive error:

Modules/common.h:9:20: fatal error: Python.h: No such file or directory
 #include "Python.h"
                    ^
compilation terminated.
error: command 'gcc' failed with exit status 1

I'm doing this inside my virtual environment (python -m venv)

I was trying to find answer for my question here:

Steps which were made in order to try to fix the error but didn't:

yum install rh-python36-python-devel.x86_64

I have also checked if Python.h file is inside one of the gcc command from pip arguments:

    gcc -pthread -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -I/opt/rh/rh-python36/root/usr/include -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DHAVE_SASL -DHAVE_TLS -DHAVE_LIBLDAP_R -DHAVE_LIBLDAP_R -DLDAPMODULE_VERSION=3.2.0 -DLDAPMODULE_AUTHOR=python-ldap project -DLDAPMODULE_LICENSE=Python style -IModules -I/me01/apps/onetick/apps/temp/venv2/include -I/opt/rh/rh-python36/root/include/python3.6m -c Modules/LDAPObject.c -o build/temp.linux-x86_64-3.6/Modules/LDAPObject.o

And the Python.h is not located inside all above locations, it is inside /opt/rh/rh-python36/root/usr/include/python3.6m/Python.h. Question is:

How to modify gcc command which is executed by pip?

PS Also tried

 "pip command here" --global-option=build_ext --global-option="-l /path/to/libraries/"

PSS I have found workaround:

Copy libraries inside venv/include.

J. Doe
  • 117
  • 1
  • 11

1 Answers1

1

As nobody answered question here is the solution. I don't know exactly when, why and under what circumstances gcc is executed during pip install command, however in our linux system there is CC variable which in my configuration is set to "gcc" probably because by yum install devtoolset-8. When I set CC command to below one, gcc knew where also to look for libraries:

export CC="gcc -I/opt/rh/rh-python36/root/usr/include/python3.6m/"

after this pip install python-ldap worked well.

Knowledge:

https://developers.redhat.com/HW/gcc-RHEL-7/

https://gcc.gnu.org/onlinedocs/gfortran/Option-Summary.html#Option-Summary

J. Doe
  • 117
  • 1
  • 11