pyinstaller 之后的 Python 复制

问题描述 投票:0回答:1

我正在使用 pyinstaller --onefile -w script.py 将 python 脚本转换为 exe。 但是,转换后我尝试运行该脚本,但它多次重复自身。

我半年前也做过同样的事情,但我更新了代码版本,因此我必须再做一次,但无论我做什么,它总是重复运行。

这可能与我的子流程代码有关:

zip_files = [f for f in os.listdir(data_analysis_folder) if f.endswith(".zip")  # file should end with .zip as extension
             and os.path.getsize(os.path.join(data_analysis_folder, f)) > 2048]  # should be bigger than 2kb to convert

zip_files_zipped = len(zip_files)
errors = []
for zip_file in zip_files:
    file_path = os.path.join(data_analysis_folder, zip_file)
    result = subprocess.Popen([program, "x", "-y", "-p" + password_customer, file_path, "-o" + data_analysis_folder],
                             stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
    result.wait()
    # The -y argument in the subprocess run confirms the replacement of the files automatically

    if result.returncode != 0:
        print(f"Error extracting {zip_file}: {result.stderr}")
        errors.append(f'Error extracting {zip_file}: {result.stderr}')
        errors_df = pd.DataFrame(errors)
        errors_df.to_csv(data_analysis_folder + str("/errors_zipping.csv"), index=False, decimal=",")

有人知道为什么会发生这种情况吗?

谢谢,

python pyinstaller
1个回答
0
投票

在导入其他模块之前使用以下代码启动该过程已解决该问题:

首先仅导入轻量级模块

导入多重处理

if name == 'main': multiprocessing.freeze_support()

© www.soinside.com 2019 - 2024. All rights reserved.