Search code examples
python-3.xwindows-10pyinstaller

FileNotFoundError: while running *exe file of python source code generated by pyinstaller


Python code runs smoothly in python ILDE ( python version3.9.5). Then i converted *.py file into *.exe by pyinstaller. When running *.exe file , it shows error "FileNotFound" which does not appear during execution of *.py file in python ILDE.

Here is the snapshot of error: enter image description here

Error: Exception in Tkinter callback

Traceback (most recent call last):

File "tkinter_init_.py", line 1892, in call

File "gui_script.py", line 284, in execute

File "script_lsprepost_report.py", line 80, in func_report_automation

File "func_files\lsp_output.py", line 25, in func_output_result

FileNotFoundError: [Errno 2] No such file or directory: 'D:/Glass_failure/M22_ball_drop/Iter_06_03/for_script/script_output/pid_4/Von_mises_stress_4.txt'

Please note that file path which was not found actually exists. I checked it manually by putting the whole path in address bar in windows machine.


Solution

  • Yeah I have found out the solution.

    Code is to execute subprocess which generates some text file. After that those text file are to be read. But Python code was executing all lines simultaneously. Hence before subprocess generates those text files, next line immediately started executing and eventually throws error as FileNotFound Error.

    So to make code execute every line sequentially i did following in subprocess.

    prog = subprocess.Popen(batfile_path, stdout=subprocess.PIPE,stderr=subprocess.PIPE) out, err = prog.communicate()