I'm facing an issue when trying to download and replace files in a Python application using PyInstaller. My application consists of downloading files from the internet and replacing existing ones locally. (Update my game files).
The code works perfectly fine when I run the Python script directly (.py), but when I generate an executable using PyInstaller (pyinstaller --onefile --noconsole --icon=icone.ico PWULauncher.py), the downloaded files are saved with a temporary format with 0 bytes (e.g., .1ad61sadtemp) and are not replaced correctly.
Additionally, the function responsible for starting the game also does not work when running the executable, same problem.
I've tried several solutions, such as running the executable as an administrator, setting folder permissions, and using different flags in PyInstaller, but the issue persists.
Here's the code snippet responsible for downloading and replacing files:
# Code snippet responsible for downloading and replacing filesdef DownloadFile(self, url, destination): try: gdown.download(url, destination, quiet=False) print("File downloaded successfully:", destination) except Exception as e: print("Error downloading the file:", e)# Calling the function to download a fileself.DownloadFile("FILE_URL", "LOCAL_DESTINATION")Here's the code for start my game:
# Code snippet responsible for starting the gamedef start_game(self, game_exe_path, username, password, character_name, idx): script_dir = os.path.dirname(os.path.abspath(__file__)) # Get the script directory current_dir = os.getcwd() # Store the current directory os.chdir(script_dir) # Change to the script directory game_dir = os.path.join(script_dir, "game") # Define the game directory os.chdir(game_dir) # Change to the game directory try: if os.path.exists(game_exe_path): subprocess.Popen([game_exe_path, 'startbypatcher', f'user:{username}', f'pwd:{password}', f'role:{character_name}'], creationflags=subprocess.CREATE_NO_WINDOW) # Add the new game window to the list self.game_windows.append(game_exe_path) # Add hotkey for the new window hotkey = f'ctrl+shift+{idx}' self.hotkeys.append(hotkey) try: keyboard.add_hotkey(hotkey, lambda idx=len(self.game_windows) - 1: self.focus_window(idx)) print(f"Hotkey '{hotkey}' added successfully for the window {len(self.game_windows)}") except Exception as e: print(f"Error adding hotkey '{hotkey}':", e) else: messagebox.showerror("Error", "The game executable was not found.") finally: os.chdir(script_dir) # Restore the original directoryDoes anyone have any insights or suggestions on what might be causing these issues when running the application as an executable? (also occurs as .pyw)
Any help or guidance would be greatly appreciated!
And if it helps, my imports:
import tkinter as tkfrom tkinter import messagebox, ttkimport osimport threadingimport gdownimport jsonimport subprocessimport timeimport pygetwindow as gwimport keyboardimport win32guiimport win32conI'm facing an issue in a Python application using PyInstaller, the code works perfectly fine when I run the Python script directly (.py).
I've tried several solutions, such as running the executable as an administrator, setting folder permissions, and using different flags in PyInstaller, but the issue persists.