PIP3 compile not working on Catalina

pythonxcode

On my Mac (OSX 10.15.7) I try to install something using pip3:

pip3 install ovirt-engine-sdk-python

I get a GCC error:

gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -I/usr/local/opt/ruby/include -I/usr/include/libxml2 -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -c ext/ov_xml_reader.c -o build/temp.macosx-10.9-x86_64-3.9/ext/ov_xml_reader.o
    ext/ov_xml_reader.c:20:10: fatal error: 'libxml/xmlreader.h' file not found
    #include <libxml/xmlreader.h>
             ^~~~~~~~~~~~~~~~~~~~
    1 error generated.
    error: command '/usr/bin/gcc' failed with exit code 1

I suspect this has something to do with where the C headers are located, and GCC nog finding them…

The suggestion to work around this is to do:

export CPATH=`xcrun --show-sdk-path`/usr/include

But this does not work. I keep getting the error.

How do I get this to work?

Best Answer

I found out that this would work:

pip3 install --global-option=build_ext  --global-option="-I`xcrun --show-sdk-path`/usr/include/libxml2" ovirt-engine-sdk-python

This specifically adds the path to libxml2 to the include path. How to solve this in a more general way I do not know however.