If you are using python imgkit to convert a html to an image, you may get this error: Fix OSError: No wkhtmltoimage executable found: “b””. In this tutorial, we will introduce you how to fix this error.
Look at this example code:
import imgkit ok = imgkit.from_string('Hello!', 'out.jpg')
Run this code, you may get:
How to fix this error?
You can do as follows:
Install wkhtmltopdf
You can download wkhtmltopdf here: https://wkhtmltopdf.org/downloads.html
Select one to download and install.
As to us, we select 64-bit.
Find the path of wkhtmltoimage
After having installed wkhtmltopdf, you should find the path of wkhtmltoimage.
As to us, the path is:E:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe. You should find your own path.
Set wkhtmltoimage path in imgkit
We should tell imgkit where to find the wkhtmltoimage.exe, we can do like this:
config = imgkit.config(wkhtmltoimage=r'E:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe') ok = imgkit.from_string('Hello!', 'out.jpg',config=config) if ok: print("successful") else: print("failed")
Then this error is fixed.