I've been trying to save some HTML into PDF using Weasyprint, but I get the error message cannot use unpack() on <cdata 'char *' NULL>
I believe this is a MacOS M1-related issue, given that the same code has been tested on a Windows computer and it seemed fine.
Here is a minimum setup of the code:
import weasyprint
def createpdf():
html = weasyprint.HTML(filename=f"./test.html", encoding='UTF-8')
html.write_pdf(f"./test.pdf")
if __name__ == '__main__':
createpdf()
And the HTML I am using is:
<html lang="en-US">
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width; initial-scale=1.0;" />
</head>
<body>
<div>
<p>Test</p>
</div>
</body>
</html>
I am running a conda-based virtual environment (Python 3.9) and have
$ conda install -c conda-forge fontconfig pango harfbuzz
I have attempted to use PyCharm's debugger to look into the code step by step and have found that:
I could not, however, understand why it fails. Could anybody help?
Though I could not figure out exactly where the issue lay, I managed to solve it by reinstalling Weasyprint and its dependencies on my virtual environment.
$ brew install python pango libffi
$ pip install weasyprint
$ conda install -c conda-forge fontconfig pango harfbuzz gtk2