简体   繁体   中英

After turning a python file into a .exe file the barcode module stops working

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.

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'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM