2016-11-28 9 views
0

pyinstaller(またはpy2exeまたはcxfreeze)を使用して、次のPythonスクリプトを1つの実行可能ファイルにバンドルするときに問題があります。私はスペースを節約しようとしてきたpyinstallerコードだけを含めていますが、誰かが他のプログラムと連携させるためのアイデアがあれば、私に知らせてください。tkinterのpythonスクリプトEXEの作成

pyinstaller --hidden-import=matplotlib --hidden-import=numpy --hidden-import=tkinter --windowed --one-file script.py 

私は、上記のバリエーションを試してみた、と私はEXEファイルを開こうとすると、エラーを「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を使用していますが、他の誰かがそれを素晴らしいバージョンにすることができるのであれば、私は他のバージョンを試しましたが、まだ運がありません。

+0

で実行する必要がありますか?使用されるdllの変更のために3.5+にいくつかの問題があります。 –

+0

私は3.5 +を主に使用していましたが、私は他のバージョン(2.7、3.4)を使ってvirtualenvを使ってみました –

答えて

0

このチュートリアルでは、cx_freezeを使用しています。私はCX凍結は、Python 3.5で動作していないと考えているが、私はPythonで実行ファイルのためにそれを使用しました2.7

tutorial

0

ここではWindowsを使用している、少なくとも場合は、あなたのコードをコンパイルする必要があるコードスニペットです。 Tomasz Plaskota氏によると、Python 3.5のcx_freezeとtkinterにはいくつかの新しい問題があります。カスタムの調整で解決する必要があります。すべてのファイルパスで交換する必要があります

C:\Program Files (x86)\Python 3.5 

あなたのpythonパスに。

from cx_Freeze import setup, Executable, hooks 
# NOTE: you can include any other necessary external imports here aswell 


import os 
os.environ['TCL_LIBRARY'] = r"C:\Program Files (x86)\Python 3.5\tcl\tcl8.6" 
os.environ['TK_LIBRARY'] = r"C:\Program Files (x86)\Python 3.5\tcl\tk8.6" 

includefiles = [r"C:\Program Files (x86)\Python 3.5\DLLs\tcl86t.dll",r"C:\Program Files (x86)\Python 3.5\DLLs\tk86t.dll"] # include any files here that you wish 
includes = ['tkinter.filedialog'] 
excludes = [] 
packages = [] 

exe = Executable(
# what to build 
    script = "cx_freeze_example.py", # the name of your main python script goes here 
    initScript = None, 
    base = 'Win32GUI', # if creating a GUI instead of a console app, type "Win32GUI" 
    targetName = "cx_freeze_example.exe", # this is the name of the executable file 
    icon = None # if you want to use an icon file, specify the file name here 
) 

setup(
# the actual setup & the definition of other misc. info 
    name = "cx_freeze example", # program name 
    version = "1.0", 
    description = '', 
    author = "", 
    options = {"build_exe": {"excludes":excludes,"packages":packages, 
     "include_files":includefiles,"includes": includes}}, 
    executables = [exe] 
) 

このコードは、メインのスクリプトと同じフォルダ内にあり、あなたは何のpythonのバージョンを使用している

関連する問題