Error: Module Not Found

I’ve created a custom app in Bench. My intention is to call a Python function from Print Template by Jinja.

the custom app function is ass follow:

import frappe
from io import BytesIO

@frappe.whitelist()
def rhk_generate(payload):
            import barcode
            from barcode import Code128
            from barcode.writer import SVGWriter
            
            raw_barcode = BytesIO()
            Code128(payload, writer=SVGWriter()).write(raw_barcode)
            return raw_barcode

and on the jinja print template, I simply call:

<svg>{{ rhk_generate('123456789') }}</svg>

However, when I open the template, the error mentioned is:

Error in print format on line 1: No module named 'barcode'

I’ve tried to move the import bits above the def and still the same error displayed. I’ve tried to run the python function interactively and it works very well. Any thing I missed?

Thanks.