0

I have python program which calculates somethings. I created a ui for this with using tkinter lib. It works very fine with Anaconda and VSCode. Then I decided to convert it to .exe. But when I'm trying to this exe created when I'm trying to open this exe it waits then throws "Failed to exe error". I used pyinstaller then I tried:
pyinstaller --onefile --noconsole --windowed root.py
pyinstaller --onefile root.py
pyinstaller --onefile --noconsole root.py
pyinstaller --onefile -w 'root.py'   
pyinstaller --noconsole --onefile -w .\root.py 

and etc. commands. Then I tried to use auto-py-to-exe But error is still the same. (Selected "one file" and "windows based")). The output of auto-py-to-exe and pyinstaller:

Running auto-py-to-exe v2.8.0
Building directory: C:\Users\Asus\AppData\Local\Temp\tmpc15upm7e
Provided command: pyinstaller --noconfirm --onefile --windowed  "C:/Users/Asus/Desktop/py-exe/root.py"
Recursion Limit is set to 5000
Executing: pyinstaller --noconfirm --onefile --windowed C:/Users/Asus/Desktop/py-exe/root.py --distpath C:\Users\Asus\AppData\Local\Temp\tmpc15upm7e\application --workpath C:\Users\Asus\AppData\Local\Temp\tmpc15upm7e\build --specpath C:\Users\Asus\AppData\Local\Temp\tmpc15upm7e
128258 INFO: PyInstaller: 4.2
128270 INFO: Python: 3.9.0
128279 INFO: Platform: Windows-10-10.0.18362-SP0
128292 INFO: wrote C:\Users\Asus\AppData\Local\Temp\tmpc15upm7e\root.spec
128310 INFO: UPX is not available.
128348 INFO: Extending PYTHONPATH with paths
['C:\\Users\\Asus\\Desktop\\py-exe',
 'C:\\Users\\Asus\\AppData\\Local\\Temp\\tmpc15upm7e']
128395 INFO: checking Analysis
128403 INFO: Building Analysis because Analysis-00.toc is non existent
128410 INFO: Initializing module dependency graph...
128430 INFO: Caching module graph hooks...
128477 WARNING: Several hooks defined for module 'win32ctypes.core'. Please take care they do not conflict.
128510 INFO: Analyzing base_library.zip ...
133726 INFO: Processing pre-find module path hook distutils from 'c:\\users\\asus\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-distutils.py'.
133731 INFO: distutils: retargeting to non-venv dir 'c:\\users\\asus\\appdata\\local\\programs\\python\\python39\\lib'
137811 INFO: Caching module dependency graph...
138063 INFO: running Analysis Analysis-00.toc
138104 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by c:\users\asus\appdata\local\programs\python\python39\python.exe
138236 WARNING: lib not found: api-ms-win-core-path-l1-1-0.dll dependency of c:\users\asus\appdata\local\programs\python\python39\python39.dll
138251 INFO: Analyzing C:\Users\Asus\Desktop\py-exe\root.py
138304 INFO: Processing module hooks...
138312 INFO: Loading module hook 'hook-difflib.py' from 'c:\\users\\asus\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
138321 INFO: Excluding import of doctest from module difflib
138328 INFO: Loading module hook 'hook-distutils.py' from 'c:\\users\\asus\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
138349 INFO: Loading module hook 'hook-distutils.util.py' from 'c:\\users\\asus\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
138359 INFO: Excluding import of lib2to3.refactor from module distutils.util
138365 INFO: Loading module hook 'hook-encodings.py' from 'c:\\users\\asus\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
138564 INFO: Loading module hook 'hook-heapq.py' from 'c:\\users\\asus\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
138575 INFO: Excluding import of doctest from module heapq
138582 INFO: Loading module hook 'hook-lib2to3.py' from 'c:\\users\\asus\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
138704 INFO: Loading module hook 'hook-multiprocessing.util.py' from 'c:\\users\\asus\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
138719 INFO: Excluding import of test.support from module multiprocessing.util
138725 INFO: Excluding import of test from module multiprocessing.util
138734 INFO: Loading module hook 'hook-pickle.py' from 'c:\\users\\asus\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
138740 INFO: Excluding import of argparse from module pickle
138749 INFO: Loading module hook 'hook-sysconfig.py' from 'c:\\users\\asus\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
138760 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from 'c:\\users\\asus\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
138774 INFO: Loading module hook 'hook-xml.py' from 'c:\\users\\asus\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
138963 INFO: Loading module hook 'hook-_tkinter.py' from 'c:\\users\\asus\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
139287 INFO: checking Tree
139290 INFO: Building Tree because Tree-00.toc is non existent
139299 INFO: Building Tree Tree-00.toc
139439 INFO: checking Tree
139441 INFO: Building Tree because Tree-01.toc is non existent
139451 INFO: Building Tree Tree-01.toc
139656 INFO: checking Tree
139665 INFO: Building Tree because Tree-02.toc is non existent
139675 INFO: Building Tree Tree-02.toc
139747 INFO: Looking for ctypes DLLs
139845 INFO: Analyzing run-time hooks ...
139863 INFO: Including run-time hook 'c:\\users\\asus\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_multiprocessing.py'
139888 INFO: Including run-time hook 'c:\\users\\asus\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth__tkinter.py'
139912 INFO: Looking for dynamic libraries
140489 INFO: Looking for eggs
140497 INFO: Using Python library c:\users\asus\appdata\local\programs\python\python39\python39.dll
140503 INFO: Found binding redirects: 
[]
140517 INFO: Warnings written to C:\Users\Asus\AppData\Local\Temp\tmpc15upm7e\build\root\warn-root.txt
140656 INFO: Graph cross-reference written to C:\Users\Asus\AppData\Local\Temp\tmpc15upm7e\build\root\xref-root.html
140807 INFO: checking PYZ
140819 INFO: Building PYZ because PYZ-00.toc is non existent
140829 INFO: Building PYZ (ZlibArchive) C:\Users\Asus\AppData\Local\Temp\tmpc15upm7e\build\root\PYZ-00.pyz
142169 INFO: Building PYZ (ZlibArchive) C:\Users\Asus\AppData\Local\Temp\tmpc15upm7e\build\root\PYZ-00.pyz completed successfully.
142228 INFO: checking PKG
142237 INFO: Building PKG because PKG-00.toc is non existent
142238 INFO: Building PKG (CArchive) PKG-00.pkg
147925 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
148025 INFO: Bootloader c:\users\asus\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\bootloader\Windows-64bit\runw.exe
148035 INFO: checking EXE
148041 INFO: Building EXE because EXE-00.toc is non existent
148051 INFO: Building EXE from EXE-00.toc
148070 INFO: Copying icons from ['c:\\users\\asus\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\bootloader\\images\\icon-windowed.ico']
148233 INFO: Writing RT_GROUP_ICON 0 resource with 104 bytes
148241 INFO: Writing RT_ICON 1 resource with 3752 bytes
148254 INFO: Writing RT_ICON 2 resource with 2216 bytes
148265 INFO: Writing RT_ICON 3 resource with 1384 bytes
148274 INFO: Writing RT_ICON 4 resource with 38188 bytes
148286 INFO: Writing RT_ICON 5 resource with 9640 bytes
148299 INFO: Writing RT_ICON 6 resource with 4264 bytes
148313 INFO: Writing RT_ICON 7 resource with 1128 bytes
148358 INFO: Updating manifest in C:\Users\Asus\AppData\Local\Temp\tmpc15upm7e\build\root\runw.exe.6hzosn3f
148390 INFO: Updating resource type 24 name 1 language 0
148434 INFO: Appending archive to EXE C:\Users\Asus\AppData\Local\Temp\tmpc15upm7e\application\root.exe
148666 INFO: Building EXE from EXE-00.toc completed successfully.

And also here is my program codes:

from tkinter import *
from tkinter import filedialog
from scipy import linalg
import numpy as np
import pandas as pd
from numpy import savetxt
from datetime import datetime
import os
label_file_explorer = ''
def browseFiles():
    global label_file_explorer
    filename = filedialog.askopenfilename(initialdir = "/", title = "Select a File", filetypes = (("Text files","*.xlsx*"),("all files","*.*")))    
    label_file_explorer.configure(text="Selected: "+filename)
    openFile(filename)

def openFile(filename):
    df = pd.DataFrame(pd.read_excel(filename)) 
    print(df)
    solve(df)

def create_roots_excel(roots):
    //some formatting
    dfr = pd.DataFrame(root_vals)
    path_filename = 'results-' + datetime.now().strftime("%d-%m-%Y %H.%M") + '.xlsx'
    desktop = os.path.join(os.path.join(os.environ['USERPROFILE']), 'Desktop') 
    path = desktop+'\\'+path_filename
    dfr.to_excel(path, sheet_name='Res', index = False)

def solve(df):
    //some calculations with math then get some results
    create_roots_excel(results)

def start_ui():
    global label_file_explorer
    window = Tk()
    window.title('Solver')
    window.geometry("500x500")
    window.config(background = "white")
    label_file_explorer = Label(window, 
                                text = "File:",
                                width = 100, height = 4, 
                                fg = "blue")    
    button_explore = Button(window, 
                            text = "Search",
                            command = browseFiles) 
    button_exit = Button(window, 
                        text = "Exit",
                        command = exit) 
    label_file_explorer.grid(column = 1, row = 1)

button_explore.grid(column = 1, row = 2)

button_exit.grid(column = 1,row = 3)
window.mainloop()

def main():
    start_ui()

if __name__ == "__main__":
    main()

I thought it caused by tkinter. But when looked for other examples other people's exe works fine. What might be reason of this error? I'm trying various commands on suggestions in other stackoverflow's questions. But still the same.

fordev
  • 65
  • 7
  • You gave us a code that is not working (undaclared variables and wrong comments for the language). Take a look [here](https://stackoverflow.com/a/63762944/5532710) – Carlo Zanocco Mar 20 '21 at 09:00
  • This comments are not for python cause there is real calculations on my real codes. But I didn't want to share them. Cause they are actually basic calculations and I don't think they are reason of this error. However, I shared my code parts which includes potential error reason like "os.path.join, import tkinter and etc." In a nutshell, my code is working but don't think them as python comment line. I wrote them instead of my calculations. – fordev Mar 20 '21 at 09:10

0 Answers0