miércoles, 18 de mayo de 2022

IO Error:Cannot open image while generating barcode after freezing using py2exe

I have used pyBarcode library to generate Barcode in my software and its works perfectly fine while I load it from command line but once I freeze the entire software using py2exe I am getting IO error while generating the barcode.

File "panels.pyc", line 383, in generate
File "barcodeGenerator.pyc", line 9, in generate
File "barcode\base.pyc", line 68, in save
File "barcode\codex.pyc", line 251, in render
File "barcode\base.pyc", line 103, in render
File "barcode\writer.pyc", line 188, in render
File "barcode\writer.pyc", line 280, in _paint_text
File "PIL\ImageFont.pyc", line 248, in truetype
File "PIL\ImageFont.pyc", line 146, in __init__
IOError: cannot open resource  

The solution is quite strange and it is mentioned in IO Error:Cannot open image while generating barcode after freezing using py2exe but what you need to change has changed a tad bit so felt I could make this thread to help any beginners not knowing how to fix this.

The solution is to change this line of code:

self.font_path = os.path.join(PATH, "fonts", "DejaVuSansMono.ttf")

In the file writer.py in C:\Users\TERMINTATOR\AppData\Local\Programs\Python\Python310\Lib\site-packages\barcode .

To this:

self.font_path = 'arial.ttf'
https://stackoverflow.com/questions/71448645/after-turning-a-python-file-into-a-exe-file-the-barcode-module-stops-working

No hay comentarios:

Publicar un comentario