I’m converting my python script to an exe using pyinstaller –onefile -w script.py.
However, after the conversion I tried to run the script but it duplicates itself multiple times.
I did the same half a year ago, but I updated my version of the code, hence I have to do it again, but whatever I do, it always runs in duplicate.
It could be that it has to do with my subprocess piece of code:
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=",")
Does anybody has an idea of why this could happen?
Thanks,