Improve error message and docs saying C compiler required to build lxml
![](https://secure.gravatar.com/avatar/1ba43be0f0fa394a3efc2d55bb2c61d9.jpg?s=120&d=mm&r=g)
Dear lxml developer community, Recently, I tried to build lxml from source because I wanted to better understand how the library worked. It took me a while, but I eventually was successful. In the process, I thought of ways it could be possible to contribute to error messages and documentation to make the process easier for future developers, and I was wondering if I or someone else could implement them. Specifically, as I am new to C compilation, I had forgotten to set up the C compiler. I ran `python3 setup.py build --with-cython --with-xml2-config=/usr/bin/xml2-config`. From my current understanding, the call to _build_ext.run(self) in line 235 of setupinfo.py (as of commit 97e6a1a) fails with a CompileError because the compiler executable didn't exist. Then, setupinfo.py tries to test if the user has libxml2 installed by a call to compiler.has_function with a function in libxml2, in lines 248-253. This fails too when the C compiler is not set up, leading to the hard-coded error printed in lines 257-261. This error message suggests that libxml2 is not installed correctly, whereas I had indeed installed libxml2 through Debian's apt package manager. I looked at the source code of distutils.ccompiler.has_function, and under the hood the function has_function writes a temporary simple C file with the function from the argument, and tries to compile it. If the compile fails for any reason, it returns False. This leads to the misleading False output from has_function, which implies that libxml2 is not installed when really the compiler executable just didn't exist in order to test it. I turn, this leads to that error message mentioned above being printed. I solved the problem eventually by adding `build-essential` and `gcc` to a `sudo apt install` command before I ran the build, thereby installing the needed C compiler and tools. I thought of two ways to improve error messages in the code, and also thought we might add something to the documentation. Regarding the error messages, we could explicitly run a check that the ccompiler executable actually exists and print out an error otherwise. Short of that, we could at least improve the hard-coded error message to mention the possibility that the compiler is not installed or the configured correctly. And, maybe add a comment to setupinfo.py saying that has_function returns False if the compiler isn't set up right. Regarding the documentation, the page https://lxml.de/build.html already makes it quite clear that the developer building lxml needs to install the development versions of libxml2 and libxslt first. Perhaps, to help those new to C compilation like me, there could also be a reminder that you need a working C compiler. I hope my message is helpful and can improve the error messages and documentation. Thanks, Abe Polk
participants (1)
-
abepolk@gmail.com