2017-10-27 6 views
1

자세한 내용 :이 프로그램은 AT를 실행하지 않고 명령 프롬프트를 열고 갑자기 종료됩니다 ... Heres my setup.py 파일 ... 나는 다른 문제가 발생하지 않도록 os를 가져오고 tcl 및 tk에 대한 링크를 추가했습니다. 그 문제를 해결 한 후 이제는 원시 Python 코드에서 .exe를 성공적으로 빌드 할 수 있지만 새로 만든 .exe 파일을 열면 ... 명령 프롬프트 화면을 열어서 다시 닫습니다. . 나는 tk.mainLoop() 또는 tkinter 일반적으로 일부 빌드 오류가 있다고 가정하고 있습니까? 또한 수학 모듈과 tkinter.font 및 tkinter.messagebox와 같은 몇 가지 다른 tkinter 항목을 가져옵니다. 내가 나 cx_Freeze 및 파이썬 - 투 - 실행 일반적으로 프로그램/모듈 ...cx_Freeze가있는 실행 파일 (.exe)과 파이썬 파일 (.exe)의 문제

import os 
from cx_Freeze import setup, Executable 
os.environ['TCL_LIBRARY'] = 'c:/python36-32/tcl/tcl8.6' 
os.environ['TK_LIBRARY'] = 'c:/python36-32/tcl/tk8.6' 
base = None 


executables = [Executable("formulas_tkinter_replace2.py", base=base, icon="pi-outline-128.ico")] 
packages = ["tkinter", "math"] 
options = { 
    'build_exe': { 

     'packages':packages, 
    }, 
} 

setup(
    name = "Formula", 
    version = "1.0", 
    description = 'Mathematics made easy...', 
    executables = executables 
) 
+0

사용중인 OS는 무엇입니까? – Simon

+0

해당 Windows. – Simon

+0

예, 죄송합니다. AFK에갔습니다. Windows 10을 구체적으로 지정하십시오. –

답변

0

기본적으로 Tk와 Tcl DLL은 모두 빠져 있습니다. 이 문제를 해결하는 데는 두 가지 방법이 있습니다.

1)은 해킹의 더 만 가끔 작동하지만 점검이 경우 :

복사 tcl86t.dlltk86t.dll 당신의 exe의 위치에 파이썬 설치에서. 이것들은 Python36-32/DLLs에서 찾을 수 있습니다. 그게 전부 야.

2) 이런 일을하는 것입니다 할 수있는 '적절한'방법 : 실행하기 전에이 넣어 :

files = {"include_files": ["C:/File_to_python/Python36-32/DLLs/tcl86t.dll", "C:/File_to_python/Python36-32/DLLs/tk86t.dll"]} 

options = { 
    'build_exe': { 

     'packages':packages, 
     'build_exe':files 
    }, 
} 

당신이 한 일의 자리에 전에.


편집 : 이 스크립트는 작동해야합니다. 필자가 제공 한 설치 스크립트를 완전히 다시 작성했지만 본질적으로 올바르지 만 tcl8.6 파일을 찾을 수 없으며 include_files 기능을 사용하지 않아 오류가 나타났습니다. 이것은 수동으로 할 수 있습니다.

from cx_Freeze import setup, Executable 

import os 
os.environ['TCL_LIBRARY'] = "FilePathToPython/Python36-32/tcl/tcl8.6" 
os.environ['TK_LIBRARY'] = "FilePathToPython/Python36-32/tcl/tk8.6" 
files = {"include_files":["FilePathToPython/Python36-32/DLLs/tcl86t.dll", "FilePathToPython/Python36-32/DLLs/tk86t.dll", "pi-outline-128.ico"], "packages": ["tkinter"]} 

base = None 
setup(name = "Name of exe", 
     version = "0.0", 
     author = "Reader", 
     description = "compile with setup.py build", 
     options = {"build_exe": files}, 
     executables = [Executable("formulas_tkinter_replace2.py", icon="pi-outline-128.ico", base=base)]) 

그냥 필요한 것을 바꿉니다.

이미 말했듯이. base = 'Win32GUI'

+0

예, 저는 창문을 사용하고 있습니다. AFK에 가면 죄송합니다. 나는 이것을 시도 할 것이다. 프로그램이 전혀 실행되고 있지 않다는 것을 분명히하기 위해 메인 게시물을 편집했습니다. 작업중인 프로그램에 빠른 명령 줄 플래시가 나타나지 않도록하고 싶지 않습니다. 난 그냥 실제로 수행 할 수있는 진행 상황을 원한다면 나는 커맨드 라인 깜박이와 함께있을거야 : ( –

+0

아, 내가 다른 모습을 보일거야. 오류 메시지가있다. 너무 빨리되면 명령 프롬프트에서 실행 – Simon

+1

cx_freeze로 파이썬 코드를 다시 빌드 한 후 'Win32GUI'를 추가 한 후 'build'폴더/디렉토리에 새 .exe 파일을 열면 이제는 더 이상 표시되지 않는 임의의 명령 프롬프트가 \ 사라집니다. 눈 깜박임. 이제 14 번째 줄에 추적 오류가 있음을 설명하는 창 오류 상자가 나타납니다. IDE와 동일한 방식으로 정확한 코드 줄을 나열한 오류 상자를 본적이 없습니다. 오류 정보에 .. –

0

다운로드 pyInstaller 중에-1.5.1 문제의 톤을 가지고와 파이썬 makespec 사용하여 봤는데, 도움을 주셔서 감사합니다 정말겠습니까. py --noconsole --onefile 'YourFile'과 python build.py 'yourfile'/ 'yourfile.spec'

+0

는 pyInstaller 중에이 계속 지원됩니다 –

+0

주셔서 감사합니다. 내가 틀렸어. –

+0

을 확인 이동 pyInstaller 중에이 파이썬 3.6 suport 한 노력 스 킬러을 Dz – Simon

0

다음은 .exe로 만들려는 python 파일의 코드입니다. 몇 백 줄의 코드를 준비하십시오 ... 죄송합니다.

__author__ = 'Mike'; 'Intuitive Design' 

from tkinter import * 
from tkinter import ttk 
from tkinter import font 
from tkinter.simpledialog import askstring 
import math 
import tkinter.messagebox 

# Variables & Core objects section 
# tk(), and ttk(): 
root = Tk() 
root.config(bg='light grey') 
root2 = ttk 
s = ttk.Style() 
s.theme_use('clam') 
s.configure('TButton', background="grey32", fg="white") 
# ______________ 
# Frames: 
frame = Frame(root) 
frame2 = Frame(root, pady=10, width=400) 
frame2.config(bg="grey10") 
# ______________ 
# Program window: 
root.title("Formula") 
root.iconbitmap('pi-outline-128.ico') 
# ______________ 
# Other: 
box = tkinter.messagebox 
output_txt = "Output here" 
pi = math.pi 
underscore = "_________________________________" 
unnecessary = 1 
code_to_get = 2 
key_binding_to_work = 3 
# _______________ 
string_num = {'one': '1', 'two': '2', 'three': '3', 'four': '4', 'five': '5', 'six': '6', 'seven': '7', 'eight': '8', 
       'nine': '9', 'ten': '10', 'eleven': '11', 'twelve': '12', 'thirteen': '13', 'fourteen': '14', 
       'fifteen': '15', 'sixteen': '16', "seventeen": '17', 'eighteen': '18', 'eightteen': '18', 'nineteen': '19' 
       , 'twenty': '20', 'twenty-one': '21', 'twenty-two': '22', 'twenty-three': '23', 'twenty-four': '24', 
       'twenty-five': '25', 'twenty-six': '26', 'twenty-seven': '27', 'twenty-eight': '28', 'twenty-nine': '29', 
       'thirty': '30', 'thirty-one': '31', 'thirty-two': '32', 'thirty-three': '33', 'thirty-four': '34', 
       'thirty-five': '35', 'thirty-six': '36', 'thirty-seven': '37', 'thirty-eight': '38', 'thirty-nine': '39', 
       'forty': '40', 'fourty': '40', 'forty-one': '41', 'forty-two': '42', 'forty-three': '43', 'forty-four': 
       '44', 'forty-five': '45', 'forty-six': '46', 'forty-seven': '47', 'forty-eight': '48', 'forty-nine': '49', 
       'fifty': '50', 'sixty': '60', 'seventy': '70', 'eighty': '80', 'ninety': '90', 'one-hundred': '100', 
       'one-thousand': '1000', 'ten-thousand': '10000', 'one-hundred-thousand': '100000', 
       'one-million': '1000000', 'one-billion': '1000000000', 'one-trillion': '1000000000000', 'vegeta': 
       '9000', 'dragon-ball-z': '9000', 'goku': '9000'} 
# ---(end of variable section)----------------------- 

# Functions: ----- 
args = [unnecessary, code_to_get, key_binding_to_work] 
def radius_input(*args): 
    try: 
     output = entry_pi.get() 
     radius = float(output) 
    except ValueError: 
     try: 
      if ord(output[0]) >= 65 and ord(output[0]) <= 90: 
       replacement = chr((ord(output[0]) + 32)) 
       output = output.replace(output[0], replacement) 
      if " " in output: 
       output = output.replace(" ", "-") 
      output = output.replace(output, string_num[output]) 
      radius = float(output) 

     except KeyError: 
      try: 
       if output[1] == '/': 
        first_num = int(output[0]) 
        second_num = int(output[2]) 
        answer = first_num/second_num 
        radius = float(answer) 
       else: 
        box.showinfo("Error Occurred", "Sorry, you forgot the input or caused an unknown error!") 
      except Exception: 
       pass 
    try: 
     A = pi * (radius ** 2) 
     A_spec = "{:,.5f}".format(A) 
     # ------Background info (True value of circle's area; no rounding at all ----- 
     print("True Value: ", A, "\n", underscore) 
     # ---------------------------------------------------------------------------- 
     print("Specific Value:", "\n", A_spec, "\n", underscore, "\n") 
     entry_pi_out.delete(0, 100) 
     entry_pi_out2.delete(0, 100) 
     entry_pi_out.insert(0, A_spec) 

     if A < A // 1 + 0.499995: 
      A_rounddown = (A // 1) 
      A_rounddown = "{:,}".format(A_rounddown) 
      print("Rounded Value:", "\n", A_rounddown, "\n", underscore, "\n") 
      entry_pi_out2.insert(0, A_rounddown) 

     elif A >= A // 1 + 0.499995: 
      A_roundup = (A // 1) + 1.0 
      A_roundup = "{:,}".format(A_roundup) 
      print("Rounded Value:", "\n", A_roundup, "\n", underscore, "\n") 
      entry_pi_out2.insert(0, A_roundup) 
     else: 
      # You created an interesting error... 
      box.showinfo("Ol' Easter Egg", """Easter egg no longer possible :(Who knows how you accessed it""") 

     hist_A = str(A_spec) 
     form_radius = "{:,}".format(radius) 
     hist_r = str(form_radius) 
     # π - storing the pi symbol in comment due to unicode string errors 
     pie = u"π" 
     hist_math = hist_r + "(r)" + "^2 * " + pie + " = " + hist_A + "\n" 
     hist_prompt = hist_math 
     history.insert(1.0, hist_prompt) 
    except UnboundLocalError: 
     pass 


args = [unnecessary, code_to_get, key_binding_to_work] 
def distance(*args): 
    try: 
     r = entry_rate.get() 
     int_r = float(r) 
    except ValueError: 
     try: 
      if ord(r[0]) >= 65 and ord(r[0]) <= 90: 
       replacement = chr((ord(r[0]) + 32)) 
       r = r.replace(r[0], replacement) 
      if " " in r: 
       r = r.replace(" ", "-") 
      r = r.replace(r, string_num[r]) 
      int_r = float(r) 
     except KeyError: 
      try: 
       if r[1] == '/': 
        first_num = int(r[0]) 
        second_num = int(r[2]) 
        answer = first_num/second_num 
        int_r = float(answer) 
       else: 
        box.showinfo("Error Occurred", "Sorry, you forgot the input or caused an unknown error!") 
      except Exception: 
       pass 
    try: 
     t = entry_time.get() 
     int_t = float(t) 
    except ValueError: 
     try: 
      if ord(t[0]) >= 65 and ord(t[0]) <= 90: 
       replacement = chr((ord(t[0]) + 32)) 
       t = t.replace(t[0], replacement) 
      if " " in t: 
       t = t.replace(" ", "-") 
      t = t.replace(t, string_num[t]) 
      int_t = float(t) 
     except KeyError: 
      try: 
       if t[1] == '/': 
        first_num = int(t[0]) 
        second_num = int(t[2]) 
        answer = first_num/second_num 
        int_t = float(answer) 
       else: 
        box.showinfo("Error Occurred", "Sorry, you forgot the input or caused an unknown error!") 
      except Exception: 
       pass 
    try: 
     D = int_r * int_t 
     form_D = "{:,.2f}".format(D) 
     print(form_D) 
     entry_dist.delete(0, 100) 
     entry_dist.insert(0, form_D) 
     form_r = "{:,.2f}".format(int_r) 
     form_t = "{:,.2f}".format(int_t) 
     hist_prompt = form_r + "(r)" + " * " + form_t + "(t)" + " = " + form_D + "\n" 
     history.insert(1.0, hist_prompt) 
    except UnboundLocalError: 
     pass 


def leftclick(event): 
    if entry_pi.get() == "Input Radius Here": 
     entry_pi.delete(0, 100) 
    else: 
     pass 

def leftclick2(event): 
    if entry_pi_out.get() == "# Exact Value...": 
     entry_pi_out.delete(0, 100) 
    else: 
     pass 

def leftclick3(event): 
    if entry_pi_out2.get() == "# Rounded Value ...": 
     entry_pi_out2.delete(0, 100) 
    else: 
     pass 

def leftclickdist(event): 
    if entry_rate.get() == "Input Rate Here": 
     entry_rate.delete(0, 100) 
    else: 
     pass 

def leftclickdist2(event): 
    if entry_time.get() == "Elapsed Time Value...": 
     entry_time.delete(0, 100) 
    else: 
     pass 

def leftclickdist3(event): 
    if entry_dist.get() == "Distance Travelled": 
     entry_dist.delete(0, 100) 
    else: 
     pass 

def save(): 
    answer = ttk.tkinter.messagebox.askquestion("Save:", "Are you sure you want to save your history?") 
    if answer == "yes": 
     file_name = askstring("File Name:", "What would you like to save it as? \n Please remember to specify\ 
    the file type (i.e. .txt, .csv, .doc, etc.)") 
     fw = open(file_name, 'w', encoding='utf-8') 
     write_var = history.get('1.0', END) 
     fw.write(write_var) 
     fw.close() 
    else: 
     pass 

def clearAll(): 
    entry_dist.delete(0, 100) 
    entry_time.delete(0, 100) 
    entry_rate.delete(0, 100) 
    entry_pi.delete(0, 100) 
    entry_pi_out.delete(0, 100) 
    entry_pi_out2.delete(0, 100) 
    history.delete(1.0, 10000.0) 
    entry_pi.insert(0, "Input Radius Here") 
    entry_pi_out.insert(0, "# Exact Value...") 
    entry_pi_out2.insert(0, "# Rounded Value ...") 
    entry_rate.insert(0, "Input Rate Here") 
    entry_time.insert(0, "Elapsed Time Value...") 
    entry_dist.insert(0, "Distance Travelled") 

y = "" 
def current_formula(y): 
    if y == "1": 
     history.grid_remove() 
     history.grid(row=6, column=0, sticky="s", padx=6, pady=100) 
     button1.grid(row=0, column=0, padx=10, pady=10) 
     entry_pi.grid(row=0, column=1, padx=10, pady=10) 
     entry_pi_out.grid(row=0, column=2, padx=10, pady=10) 
     entry_pi_out2.grid(row=1, column=2, padx=10, pady=12) 
     root.bind("<Return>", lambda x: radius_input(*args)) 
     button2.grid_remove() 
     entry_rate.grid_remove() 
     entry_time.grid_remove() 
     entry_dist.grid_remove() 
     one.config(bg="maroon") 
    elif y == "2": 
     history.grid_remove() 
     history.grid(row=6, column=0, sticky="s", padx=6, pady=100) 
     button2.grid(row=0, column=0, padx=10, pady=10) 
     entry_rate.grid(row=0, column=1, padx=10, pady=10) 
     entry_time.grid(row=1, column=1, padx=10, pady=10) 
     entry_dist.grid(row=0, column=2, padx=10, pady=12) 
     root.bind("<Return>", lambda x: distance(*args)) 
     button1.grid_remove() 
     entry_pi.grid_remove() 
     entry_pi_out.grid_remove() 
     entry_pi_out2.grid_remove() 
     one.config(bg="paleturquoise4") 
    else: 
     one.config(bg="goldenrod4") 
     try: 
      history.grid_remove() 
      entry_pi.delete(0, 100) 
      entry_pi_out.delete(0, 100) 
      entry_pi_out2.delete(0, 100) 
      entry_rate.delete(0, 100) 
      entry_time.delete(0, 100) 
      entry_dist.delete(0, 100) 
      entry_pi.insert(0, "Input Radius Here") 
      entry_pi_out.insert(0, "# Exact Value...") 
      entry_pi_out2.insert(0, "# Rounded Value ...") 
      entry_rate.insert(0, "Input Rate Here") 
      entry_time.insert(0, "Elapsed Time Value...") 
      entry_dist.insert(0, "Distance Travelled") 
      button1.grid_forget() 
      entry_pi.grid_forget() 
      entry_pi_out.grid_forget() 
      entry_pi_out2.grid_forget() 
      button2.grid_forget() 
      entry_rate.grid_forget() 
      entry_time.grid_forget() 
      entry_dist.grid_forget() 
     finally: 
      pass 
''' 
button1.grid(row=0, column=0, padx=10, pady=10) 
entry_pi.grid(row=0, column=1, padx=10, pady=10) 
entry_pi_out.grid(row=0, column=2, padx=10, pady=10) 
entry_pi_out2.grid(row=1, column=2, padx=10, pady=12) 
one.config(bg="maroon") 
''' 
# ---------------------- 

# toolbar: ----- 
toolframe = Frame(root) 
toolbar = Frame(toolframe, bg="gray7") 
# -------- 

# Main: ----- 
#  Labels --- 
one = Label(frame, pady=0, padx=20, width=31) 
one_trim = Label(frame, bg="gray24", padx=1.5) 
two = Label(toolbar, text="Formula", fg='gray34', font='broadway 24 bold italic', bg="gray10", pady=20, padx=20) 

# complicated way to underline "Formula"... would only underline the 'o' without this... uses 'font' import @ top 
f = font.Font(two, two.cget("font")) 
f.configure(underline=True) 
two.configure(font=f) 
#  ---------- 

#  Button, entry boxes, answer boxes -- 
button1 = root2.Button(frame2, text="Area of a circle ", command=radius_input) 
# very poorly written code... resulted in a random *args parameter, lambda statement, and the event to be bound to 
# 'root' [i.e. Tk()] instead of button1. Please resolve this. *args is specified above 'radius_input()'. 


entry_pi = ttk.Entry(frame2) 
entry_pi.bind("<Button-1>", leftclick) 

entry_pi_out = ttk.Entry(frame2) 
entry_pi_out2 = ttk.Entry(frame2) 
entry_pi_out.bind("<Button-1>", leftclick2) 
entry_pi_out2.bind("<Button-1>", leftclick3) 

button2 = root2.Button(frame2, text="Calculate Distance ", command=distance) 
# same backwards *args parameter as 'button1' and 'radius_input()' suffer from are in 'button2' & 'distance()' 

entry_rate = ttk.Entry(frame2) 
entry_rate.bind("<Button-1>", leftclickdist) 

entry_time = ttk.Entry(frame2) 
entry_time.bind("<Button-1>", leftclickdist2) 

entry_dist = ttk.Entry(frame2) 
entry_dist.bind("<Button-1>", leftclickdist3) 
#  ------------------------------------- 

# History text box ----- 
history = Text(one, height=20, width=30, spacing3=2.5) 
# ---------------------------- 

# -------- 

# Dropdown menu ------- 
menu = Menu(root) 
root.config(menu=menu) 
submenu = Menu(menu) 
menu.add_cascade(label="File", menu=submenu) 
submenu.add_command(label="Clear All", command=clearAll) 
submenu.add_command(label="Save", command=save) 
submenu.add_separator() 
submenu.add_command(label="Exit", command=lambda: current_formula("")) 
editmenu = Menu(menu) 
menu.add_cascade(label="Formulas", menu=editmenu) 
editmenu.add_command(label="Area of a circle", command=lambda: current_formula("1")) 
editmenu.add_command(label="Distance Formula", command=lambda: current_formula("2")) 
# ---------------------- 
# .pack ------ 
frame.pack(side="left", fill='y') 
frame2.pack(side='right', fill='y') 
one.pack(side='left', fill='y') 
one_trim.pack(side='right', fill='y') 
two.pack(side='top', pady=6) 
toolbar.pack(side="top", fill="x") 
toolframe.pack(side="top", fill='x', padx=4) 


# ----- end/loop program & execute remnant functions ----- 
current_formula(y) 
root.mainloop() 
+0

나에게 얼마나 많은 시간을 할애 해 주셔서 감사합니다. 이제는 많은 시간 동안이 진행 상황을 지연시키고 자바/안드로이드 SDK로 옮겨 왔기 때문에 좋다. –

+0

저는 기꺼이 도와 드리겠습니다. 나는 시간이 좀 걸릴지 모르지만 나는 포기하지 않을 것이다! – Simon

0

Win32GUI에 대해 질문했습니다. 솔직히 전적으로 확실하지 않다 그러나 나는 그것이 나 cx_Freeze의 문서가이 문제를 언급 Windows API.

함께 할 수있는 뭔가가 생각 :

버전 4.2.2 (, 2010 년 12 월)

사용하여 Microsoft Windows 용 Python 2 용 컴파일러.mingw32를 사용하여 컴파일 할 때 Python 2.7에서 일부 이상한 동작이 확인되었습니다.

는 Win32GUI 기본 실행 파일을 구축하기위한 마이크로 소프트 컴파일러를 사용하는 경우 -mwindows 대한 경고를 제거합니다.

이는 MinGW는 C 또는 C++ 컴파일러입니다.

그것은이 hide the console of a program에 사용 할 수 있기 때문에 의미는 Windows API를 사용할 수 있도록합니다.

위키 백과는 "Win32GUI"라는 이유에 대한 답을 것 같다 윈도우 API를 사용 않는 경우 :

사용자 인터페이스 [9] 화면 윈도우와 가장 기본적인 컨트롤을 생성하고 관리 할 수있는 기능을 제공합니다 , 단추 및 스크롤 막대, 마우스 및 키보드 입력 및 Windows의 그래픽 사용자 인터페이스 (GUI) 부분과 관련된 기타 기능을 수신 할 수 있습니다. 이 기능 단위는 16 비트 Windows에서는 user.exe에, 32 비트 Windows에서는 user32.dll에 있습니다. Windows XP 버전부터 기본 컨트롤은 공통 컨트롤 (공통 컨트롤 라이브러리)과 함께 comctl32.dll에 있습니다.

기본적으로 64 비트 컴퓨터의 경우에도 여전히 GUI가 32 비트 버전 인 것처럼 보입니다. 따라서 32 비트 버전이므로 Win32GUI로 참조합니다. Cx_Freeze 개발자는 인 64 비트 버전을 만들 때 "Win64GUI"라고 부르지 않을 것입니다.

+0

사실, 대중에게 새로운 소프트웨어를 채택하게하려면 시간이 좀 걸릴 것입니다. 몇 년 전에 저는 64 비트 시스템을 보편적으로 채택했을뿐만 아니라 128 비트 OS를보다 자유롭게 사용할 수있게 될 것이라고 생각했을 것입니다. (특히 서버에 대한 확신이 큽니다.) –

+0

@MichaelBeyer '몇 년 전에 필자는 64 비트 시스템을 보편적으로 채택했을뿐만 아니라 128 비트 OS를보다 자유롭게 사용할 수있게 될 것이라고 생각했을 것입니다.'나는 100 % 동의합니다. '라고 생각합니다. 대중에게 새로운 소프트웨어를 채택하게하려면 약간의 시간이 필요합니다. '나는 그것에 동의해야합니다. 그들은 대중도 모르게 64 비트까지 업데이트 할 수 있습니다. 마이크로 소프트가 멈추는 것처럼 보입니다. 어제 나는 마이크로 소프트의 컴파일러 인 비주얼 스튜디오 (Visual Studio)가 최근까지만해도 C의 최신 버전을 지원하지 못했다고 들었다. – Simon

+0

@MichaelBeyer 64 비트와 32 비트 소프트웨어를 모두 배포 할 수 있으며 완전히 똑같을 것입니다. – Simon