Reputation: 33
After turning a python file into a .exe file the barcode module is no longer able to save an image file of a barcode.
for example this:
from barcode import Code39
from barcode.writer import ImageWriter
myImage = Code39("0007", writer=ImageWriter(), add_checksum=False)
myImage.save("myImage.png")
Will work as a .py file but no longer as a .exe file.
Upvotes: 0
Views: 594
Reputation: 1
passing some barcodeoptions to with the save command seems to work for me.
as long as the font.ttf
file is on the computer this will work:
barCodeOptions = {
'font_size':22,
'text_distance':15,
'font_path': "arial.ttf"
}
barcode_instance.save(bcFile, barCodeOptions)
Upvotes: 0
Reputation: 33
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'
Upvotes: 2