Fix OSError: No wkhtmltoimage executable found: “b”” in Python imgkit – Python Tutorial

By | December 17, 2020

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:

Fix OSError No wkhtmltoimage executable found b in Python - Python Tutorial

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.

install wkhtmltopdf

Find the path of wkhtmltoimage

After having installed wkhtmltopdf, you should find the path of wkhtmltoimage.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *