The problem encountered in pyinstaller packaging “failed to execute script × *”

do a small tool, in the local execution OK, use pyinstaller packaging process, there are problems, in a variety of search on the Internet, can not find the specific problem point, it seems mainly because, in the process of the problem, the difference will be relatively big, so also need to analyze the specific problem.

local execution: python ******. Py

all normal, ready to use pyinstaller package to generate exe execution file;

package command: pyinstaller. Exe-dall *****. Py

execution will jump out of the command line black window and will execute normally.

package command: pyinstaller. Exe-w-dall *****. Py

execution occurs as follows:

packaging command: pyinstaller. Exe-w *****. Py

Failed to execute script ******

is later found because the log output is used in the following way:

import os
import io

class Logger(object):
    def __init__(self, filename="Default.log", path="./"):
        sys.stdout = io.TextIOWrapper(sys.stdout.buffer)
        self.terminal = sys.stdout
        # self.log = open(os.path.join(path, filename), "a", encoding='utf8')
        self.log = open(filename, "a")

    def write(self, message):
        self.terminal.write(message)
        self.log.write(message)

    def flush(self):
        pass


sys.stdout = Logger(create_detail_day() + '_grit.log', path='')#方式1

is changed as follows:

savedStdout = sys.stdout  #保存标准输出流 #方式2    
file = open(create_detail_day()+ '_zh_finlock_license_gen_log.txt', 'wt')
sys.stdout = file  #标准输出重定向至文件

then package and use the command: pyinstaller. Exe-w *****. Py

will run normally.

The -f command is added below

to package the dependent libraries and files as a whole

package command to: pyinstaller. Exe – w – F – dall * * * * * * *. Py

generates exe executable, after which the following phenomenon occurs:

packaging command: pyinstaller. Exe-w-f *****. Py

generates exe executables, which can be executed normally.

come to an end!

Read More: