我有一个Python程序,可以合并电子表格并在我的PyCharm venv中正常工作:
import pandas as pd
input_string = input("Enter each spreadsheet to merge (including its file extension), separated by spaces ")
list = input_string.split()
excel_names = list
excels = [pd.ExcelFile(name) for name in excel_names]
frames = [x.parse(x.sheet_names[0], header=None,index_col=None) for x in excels]
rowcutnum = int(input("How many header rows are there? (For NCES state data there are 7)"))
frames[1:] = [df[rowcutnum:] for df in frames[1:]]
rowcutback = int(input("How many footer rows are there? (For NCES state data there are 7)"))
frames[:-1] = [df[:-rowcutback] for df in frames[:-1]]
combined = pd.concat(frames)
combined.to_excel("Combined.xlsx", header=False, index=False)
我已经编辑了pyinstaller .spec文件,使其包含所有以.xls结尾的文件:
# -*- mode: python -*-
block_cipher = None
a = Analysis(['SpreadsheetMerge.py'],
pathex=['/Users/user/PycharmProjects/SpreadsheetMerge'],
binaries=[],
datas=[ ('*.xls', '.' ) ],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
[],
exclude_binaries=True,
name='SpreadsheetMerge',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name='SpreadsheetMerge')
运行pyinstaller生成的可执行文件时,输入两个电子表格进行合并后出现此错误:
Enter each spreadsheet to merge (including its file extension), separated by spaces CA.xls CO.xls
Traceback (most recent call last):
File "SpreadsheetMerge.py", line 10, in <module>
File "SpreadsheetMerge.py", line 10, in <listcomp>
File "site-packages/pandas/io/excel.py", line 653, in __init__
File "site-packages/pandas/io/excel.py", line 424, in __init__
File "site-packages/xlrd/__init__.py", line 111, in open_workbook
FileNotFoundError: [Errno 2] No such file or directory: 'CA.xls'
[4712] Failed to execute script SpreadsheetMerge
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
[Process completed]
如何获取程序的独立版本以成功找到文件?