我在一段python代码上运行cx-freeze时遇到问题。当我单击cx-freeze生成的可执行文件时,它总是抛出错误消息。有人可以帮忙吗? - 使用Python 3.6.1。
我还在另一段python代码上运行了cx-freeze,它运行良好。
错误信息如下:
Last login: Thu Aug 31 14:45:12 on ttys002
EMacBook-Pro:~ E$ /Users/E/PycharmProjects/ImageRename/dist/exportImageName_1 ; exit;
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/cx_Freeze/initscripts/__startup__.py", line 14, in run
module.run()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/cx_Freeze/initscripts/Console.py", line 26, in run
exec(code, m.__dict__)
File "exportImageName_1.py", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/xlwt/__init__.py", line 4, in <module>
from .Worksheet import Worksheet
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/xlwt/Worksheet.py", line 38, in <module>
from .Row import Row
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/xlwt/Row.py", line 8, in <module>
from . import ExcelFormula
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/xlwt/ExcelFormula.py", line 3, in <module>
from . import ExcelFormulaParser, ExcelFormulaLexer
ImportError: cannot import name 'ExcelFormulaParser'
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
[进程已完成]
py文件中的源代码:
import xlwt
import os
import FileDirectory_1
def walk_dir(dir):
rowindex = 1
for root, dirs, files in os.walk(dir):
for f in files:
if "jpg" in f:
table.write(rowindex,0, root)
table.write(rowindex,1, f)
# print(os.path.join(root,f))
rowindex += 1
dir = FileDirectory_1.DIR;
excelName = "imageRename.xls"
# =======Excel Style============
style = xlwt.XFStyle()
font = xlwt.Font()
font.name = "Arial"
font.bold = True
style.font = font
# ==============================
file = xlwt.Workbook()
table = file.add_sheet("ImageRename", cell_overwrite_ok=True)
table.write(0, 0, "Old File Path", style)
table.write(0, 1, "Old Image Name", style)
table.write(0, 2, "New Image Name", style)
walk_dir(dir)
file.save(os.path.join(dir, excelName))
print(excelName, " has been generated.")
答案 0 :(得分:3)
发现了这个问题。我检查了/ lib / xlwt文件夹中由cx-freeze生成的文件,找到了&#34; ExcelFormulaParser.pyc&#34;和&#34; ExcelFormulaLexer.pyc&#34;文件以某种方式丢失。添加回&#34; ExcelFormulaParser.py&#34;和&#34; ExcelFormulaLexer.py&#34;文件问题已解决。这两个文件是从我自己的xlwt文件从站点包复制到build文件夹。
答案 1 :(得分:0)
实际上,不需要复制文件。只需在cx-freeze setup.py文件中将xlwt添加为软件包依赖项即可。
例如:
build_exe_options = {"packages": [...your packages....., "xlwt"]
...............
}
我遇到了同样的问题,它将解决此问题。