我在使用pyinstaller(或py2exe或cxfreeze)將以下python腳本綁定到單個可執行文件時遇到了一些麻煩。我只包括我一直試圖節省空間的pyinstaller代碼,但如果任何人有任何想法使其與任何其他程序一起工作,請隨時通知我。當我嘗試打開該EXE文件創建tkinter python腳本的EXE
pyinstaller --hidden-import=matplotlib --hidden-import=numpy --hidden-import=tkinter --windowed --one-file script.py
我已經試過以上的變化,我不斷收到「無法執行腳本pyi_rth_pkgres」的錯誤。
import matplotlib
matplotlib.use('TkAgg')
import numpy as np
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import matplotlib.pyplot as plt
import tkinter as tk
class Application(tk.Frame):
def __init__(self, master=None):
tk.Frame.__init__(self,master)
self.createWidgets()
def createWidgets(self):
fig=plt.figure(figsize=(8,8))
ax=fig.add_axes([0.1,0.1,0.8,0.8],polar=True)
canvas=FigureCanvasTkAgg(fig,master=root)
canvas.get_tk_widget().grid(row=0,column=1)
canvas.show()
self.plotbutton=tk.Button(master=root, text="plot", command=lambda:self.plot(canvas,ax))
self.plotbutton.grid(row=0,column=0)
def plot(self,canvas,ax):
c = ['r','b','g'] # plot marker colors
ax.clear() # clear axes from previous plot
for i in range(3):
theta = np.random.uniform(0,360,10)
r = np.random.uniform(0,1,10)
ax.plot(theta,r,linestyle="None",marker='o', color=c[i])
canvas.draw()
root=tk.Tk()
app=Application(master=root)
app.mainloop()
我知道這是很模糊的,但我想我扔在那裏,看看是否任何人有任何想法,我要去哪裏錯了/可能是什麼問題。
謝謝!
編輯:我使用Python 3.5,但如果任何人都可以得到它與一個不同的版本,這將是偉大的。我試過其他版本,但仍然沒有運氣。
什麼Python版本是您使用與運行?由於所使用的dll的變化,3.5+有一些問題。 –
我主要使用3.5+,儘管我通過virtualenv嘗試了其他版本(2.7,3.4),沒有任何運氣 –