[英]Pyinstaller - Bundle excel file to onefile exe
我使用 pyinstaller 創建了一個 EXE 文件,其中包括 excel 文件。 看下面的代碼:
import pandas
from tkinter import *
sec = pandas.read_csv("sectionsize.csv")
win = Tk()
win.title('Imp vs Metric Section size')
win.geometry('320x100')
win.attributes("-topmost", True)
win.resizable(0,0)
def reset(dummy=None):
e1.delete(0, 'end')
e2.delete(0, 'end')
def conv(dummy=None):
s1 = str(e1.get())
s2 = str(e2.get())
a = s1.upper()
b = s2.upper()
if len(a)!=0 and len(b)==0:
try:
imp_index = sec[sec['Imperial']==a].index[0]
x = sec['Metric'][imp_index]
e2.delete(0, 'end')
e2.insert(END, x)
except:
x = 'Check Section size'
e2.delete(0, 'end')
e2.insert(END, x)
elif len(a)==0 and len(b)!=0:
try:
metric_index = sec[sec['Metric']==b].index[0]
y = sec['Imperial'][metric_index]
e1.delete(0, 'end')
e1.insert(END, y)
except:
y = 'Check Section size'
e1.delete(0, 'end')
e1.insert(END, y)
elif len(a)!=0 and len(b)!=0:
e1.delete(0, 'end')
e2.delete(0, 'end')
else:
pass
win.bind('<Return>', conv)
win.bind('<Escape>', reset)
l1=Label(win, text='Imperial')
l1.place(x=25, y=10)
l2=Label(win, text='Metric')
l2.place(x=25, y=50)
e1=Entry(win, width=30)
e1.place(x=90, y=10)
e1.focus_set()
e2=Entry(win, width=30)
e2.place(x=90, y=50)
win.mainloop()
exe 文件在我的計算機上打開並完美運行。 唯一的問題是此文件要求 excel 文件位於同一文件夾中。 如何在不需要外部文件的情況下將 excel 文件捆綁到 EXE 中? 任何輸入都會非常有幫助。
為此,您必須使用--add-data
標志
來自 Pyinstaller 的文檔:
捆綁什么,在哪里搜索:--add-data <SRC;DEST or SRC:DEST> 要添加到可執行文件的其他非二進制文件或文件夾。 路徑分隔符是特定於平台的,
os.pathsep
(在 >Windows 上是;
:
在大多數 unix 系統上是 :)。 此 > 選項可以多次使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.