Daniel Lee
Daniel Lee

Reputation: 51

No module named 'reportlab.graphics.barcode.code128' error when using xhtml2pdf

My code works fine when running from the terminal, but when I try to run it as an executable after compiling it, it gives me a No module named 'reportlab.graphics.barcode.code128' error. I tried uninstalling and installing it again but still outputs the same error. Any ideas?

Upvotes: 1

Views: 1426

Answers (2)

Yash Darji
Yash Darji

Reputation: 11

I encountered same issue. Turns out you need to add hidden dependencies to make it run. Thanks to Carmelo Lopez, I found the list here: https://groups.google.com/g/pyinstaller/c/-QbzffPG8Bc/m/BqyScfVJAgAJ?pli=1

hiddenimports=[ 'reportlab.graphics.barcode.common',
'reportlab.graphics.barcode.code128',
'reportlab.graphics.barcode.code93',
'reportlab.graphics.barcode.code39',
'reportlab.graphics.barcode.code93',
'reportlab.graphics.barcode.usps',
'reportlab.graphics.barcode.usps4s',
'reportlab.graphics.barcode.ecc200datamatrix']

Adding this should solve your issue.

Upvotes: 1

nanda
nanda

Reputation: 131

I had the exact same issue. The code works perfectly fine. But when built and compiled, the executable doesn't work. The cause of the error is xhtml2pdf dynamically loading reportlab.graphics.barcode. The solution is to include the entire reportlab.graphics.barcode when building the executable.

In PyInstaller this can be done with:

pyinstaller --onefile --noconsole --collect-all reportlab.graphics.barcode script.py

In nuitka:

nuitka --onefile --windows-disable-console --include-package=reportlab.graphics.barcode --include-data-dir=path_to_reportlab\graphics\barcode=barcode script.py

Upvotes: 4

Related Questions