【问题标题】:FileNotFoundError: while running *exe file of python source code generated by pyinstallerFileNotFoundError: 在运行 pyinstaller 生成的 python 源代码的 *exe 文件时
【发布时间】:2021-09-05 09:05:30
【问题描述】:

Python 代码在 python ILDE (python version3.9.5) 中运行流畅。然后我通过 pyinstaller 将 *.py 文件转换为 *.exe。在运行 *.exe 文件时,它显示错误“FileNotFound”,该错误在 python ILDE 中执行 *.py 文件时不会出现。

这是错误的快照:

错误: Tkinter 回调异常

Traceback(最近一次通话最后一次):

文件“tkinter_init_.py”,第 1892 行,在 call

文件“gui_script.py”,第 284 行,在执行中

文件“script_lsprepost_report.py”,第 80 行,在 func_report_automation 中

文件“func_files\lsp_output.py”,第 25 行,在 func_output_result 中

FileNotFoundError: [Errno 2] 没有这样的文件或目录: 'D:/Glass_failure/M22_ball_drop/Iter_06_03/for_script/script_output/pid_4/Von_mises_stress_4.txt'

请注意,未找到的文件路径实际上是存在的。我通过将整个路径放在Windows机器的地址栏中手动检查它。

【问题讨论】:

    标签: python-3.x windows-10 pyinstaller


    【解决方案1】:

    是的,我找到了解决方案。

    代码是执行生成一些文本文件的子进程。之后,将读取这些文本文件。但是 Python 代码同时执行所有行。因此,在子进程生成这些文本文件之前,下一行立即开始执行并最终抛出错误为 FileNotFound 错误。

    所以为了让代码按顺序执行每一行,我在子进程中做了以下操作。

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

    【讨论】:

      猜你喜欢
      • 2020-12-25
      • 1970-01-01
      • 2023-04-08
      • 1970-01-01
      • 2021-06-22
      • 2021-04-22
      • 1970-01-01
      • 2016-09-29
      • 2016-07-05
      相关资源
      最近更新 更多