[英]File converted to exe can't generate barcode
I tried to generate barcode and made a GUI using pyqt5 when I run it through scripts it works perfectly but when I converted the.py file to.exe file when I try to generate it, it gives many tracebacks当我通过脚本运行它时,我尝试使用 pyqt5 生成条形码并制作了一个 GUI,但是当我尝试生成它时将 .py 文件转换为 .exe 文件时,它给出了许多回溯
import pkg_resources.py2_warn
from PyQt5 import QtCore, QtGui, QtWidgets
import barcode
from barcode.writer import ImageWriter
import shutil
import os
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(607, 503)
self.pushButton = QtWidgets.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(-170, 220, 93, 28))
self.pushButton.setObjectName("pushButton")
self.horizontalLayoutWidget = QtWidgets.QWidget(Form)
self.horizontalLayoutWidget.setGeometry(QtCore.QRect(130, 180, 311, 80))
self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget")
self.horizontalLayout = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget)
self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout.setObjectName("horizontalLayout")
self.lineEdit = QtWidgets.QLineEdit(self.horizontalLayoutWidget)
self.lineEdit.setObjectName("lineEdit")
self.horizontalLayout.addWidget(self.lineEdit)
self.pushButton_2 = QtWidgets.QPushButton(self.horizontalLayoutWidget)
self.pushButton_2.setObjectName("pushButton_2")
self.horizontalLayout.addWidget(self.pushButton_2)
self.pushButton_2.clicked.connect(lambda: self.testEan(self.lineEdit.text()))
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.pushButton.setText(_translate("Form", "PushButton"))
self.pushButton_2.setText(_translate("Form", "Generate"))
def testEan(self, i):
EAN = barcode.get_barcode_class('code128')
s = '0' * (8 - len(str(i)) - 1) + str(i)
ean = EAN(s, writer=ImageWriter())
fullname = ean.save(str(i))
try:
os.mkdir("Barcode")
except FileExistsError:
pass
try:
shutil.move(fullname, "Barcode")
except:
pass
QtWidgets.QMessageBox().about(QtWidgets.QWidget(), "Info", "Success")
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Form = QtWidgets.QWidget()
ui = Ui_Form()
ui.setupUi(Form)
Form.show()
sys.exit(app.exec_())
NOTE: I have imported
pkg_resources.py2_warn
because without it when i try to execute the application it throws no module namepkg_resources.py2_warn
注意:我已经导入
pkg_resources.py2_warn
,因为没有它,当我尝试执行应用程序时,它不会抛出任何模块名称pkg_resources.py2_warn
Traceback: (most recent call last)
File "Bar.py" line 37, in <lambda>
File "Bar.py" line 51, in testEan
File "site packages\barcode\base.py" line 68 in save
File "site packages\barcode\codex.py" line 261 in render
File "site packages\barcode\base.py" line 111 in render
File "site packages\barcode\writer.py" line 226 in render
File "site packages\barcode\writer.py" line 356 in _paint_text
File "site packages\PIL\ImageFont.py" line 648 in truetype
File "site packages\PIL\ImageFont.py" line 645 in freetype
File "site packages\PIL\ImageFont.py" line 193 in __init__
OsError : cannot open resource
OS : windows 10
Python : 3.8.3
Pyinstaller : 3.6
Is there any way to overcome that traceback error?有什么办法可以克服这个回溯错误吗?
IO Error:Cannot open image while generating barcode after freezing using py2exe IO 错误:使用py2exe冻结后生成条形码时无法打开图像
as stated here you should alter or include the font in you code, so it can read it.如此处所述,您应该在代码中更改或包含字体,以便它可以读取它。 I chosed to alter the code to a "standard" font instead.
我选择将代码更改为“标准”字体。
i posted in a similar issue on the repo as well: https://github.com/WhyNotHugo/python-barcode/issues/69我也在 repo 上发布了一个类似的问题: https://github.com/WhyNotHugo/python-barcode/issues/69
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.