Python Skript zu .exe Datei fehlerhaft?

Liebes Forum,

da ich mich mit Python-Skripts nicht so gut auskenne und ChatGPT scheinbar auch oft Fehler macht, möchte ich mich an erfahrene Benutzer werden.

Warum kann ich das folgende Skript nicht in einer EXE-Datei umwandeln? Es wandelt zwar um, aber am Ende, wenn ich das Programm öffne, loopt es hin und her. Es ist ein Programm, das RAM, CPU, GPU usw. überprüfen soll. Könnt gerne eine Überschrift zum Skript da lassen. :D.

Das Skript (Python):

import os
import platform
import psutil
import subprocess
import cpuinfo
import wmi
import logging
from datetime import datetime

logging.basicConfig(filename='wininfo.log', level=logging.DEBUG)

def get_windows_version():
  return platform.win32_ver()[1]

def get_cpu_info():
  info = cpuinfo.get_cpu_info()
  cpu_count = psutil.cpu_count(logical=False)
  cpu_arch = info['arch']
  cpu_usage = psutil.cpu_percent()

  try:
    cpu_temps = psutil.sensors_temperatures(fahrenheit=False)
  except AttributeError:
    cpu_temps = None

  return cpu_count, cpu_arch, cpu_usage, cpu_temps

def get_ram_info():
  ram = psutil.virtual_memory()
  return ram.total / (1024 ** 3), ram.used / (1024 ** 3)

def get_gpu_info():
  w = wmi.WMI()
  gpus = w.Win32_VideoController()
  gpu_info = [(gpu.Caption, gpu.AdapterRAM / (1024 ** 3)) for gpu in gpus]
  return gpu_info

def get_storage_info():
  storage = psutil.disk_usage('/')
  return storage.total / (1024 ** 3), storage.free / (1024 ** 3)

def suggest_windows_upgrade():
  current_version = int(platform.win32_ver()[1].split('.')[0])

  if current_version <= 8:
    print("Recommendation: Upgrade to Windows 10 or 11.")
    choice = input("Do you want to proceed with the upgrade? (Yes/No): ")

    if choice.lower() == 'yes':
      check_system_requirements()

def check_system_requirements():
  print("Checking system requirements...")
  # Hier kannst du die Überprüfung der RAM, CPU und GPU hinzufügen
  # Beispiel:
  # if not meet_requirements():
  #  print("Your system does not meet the requirements for the upgrade.")
  #  return

def meet_requirements():
  # Hier kannst du die tatsächliche Überprüfung der Anforderungen implementieren
  # Beispiel: return check_ram() and check_cpu() and check_gpu()
  pass

def create_log_file(path, content):
  try:
    os.makedirs(path, exist_ok=True)
    timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
    log_file_path = os.path.join(path, f'computer_check_log_{timestamp}.txt')

    with open(log_file_path, 'w') as file:
      file.write(content)

    print(f"Log file has been successfully created: {log_file_path}")
  except Exception as e:
    print(f"Error creating log file: {e}")

# Windows Version Überprüfung
print("Debugging: Before Windows Version")
windows_version = get_windows_version()
print(f"Windows Version: {windows_version}")

# CPU Check
print("Debugging: Before CPU Info")
cpu_count, cpu_arch, cpu_usage, cpu_temps = get_cpu_info()
print(f"Number of CPUs: {cpu_count}")
print(f"CPU Architecture: {cpu_arch}")
print(f"CPU Usage: {cpu_usage}%")
print(f"CPU Temperatures: {cpu_temps}")

# RAM Check
total_ram, used_ram = get_ram_info()
print(f"Installed RAM: {total_ram:.2f} GB")
print(f"Used RAM: {used_ram:.2f} GB")

# GPU Check
gpu_info = get_gpu_info()
print("Graphics Cards:")

for gpu in gpu_info:
  print(f"- {gpu[0]} (VRAM: {gpu[1]:.2f} GB)")

# Storage Check
total_storage, free_storage = get_storage_info()
print(f"Installed Storage: {total_storage:.2f} GB")
print(f"Free Storage: {free_storage:.2f} GB")

# Windows Updates Check
def check_windows_updates():
  result = subprocess.run('powershell "Get-HotFix"', capture_output=True, text=True, shell=True)
  return 'No updates available' not in result.stdout
# ...

# Windows Updates Check
if check_windows_updates():
  choice = input("Windows updates are available. Do you want to install them? (Yes/No): ")
  if choice.lower() == 'yes':
    print("Installing Windows updates...")
    subprocess.run('powershell "Install-Module -Name PSWindowsUpdate -Force -AllowClobber"', shell=True)
    subprocess.run('powershell "Get-WindowsUpdate"', shell=True)
    subprocess.run('powershell "Install-WindowsUpdate -AcceptAll -AutoReboot"', shell=True)

# Windows Gültigkeit Check
suggest_windows_upgrade()

# Log-File erstellen
log_path = input("Enter the path for the log directory: ")
log_content = f"Windows Version: {windows_version}\n"
log_content += f"Number of CPUs: {cpu_count}\n"
log_content += f"CPU Architecture: {cpu_arch}\n"
log_content += f"CPU Usage: {cpu_usage}%\n"
log_content += f"CPU Temperatures: {cpu_temps}\n"
log_content += f"Installed RAM: {total_ram:.2f} GB\n"
log_content += f"Used RAM: {used_ram:.2f} GB\n"
log_content += "Graphics Cards:\n"

for gpu in gpu_info:
  log_content += f"- {gpu[0]} (VRAM: {gpu[1]:.2f} GB)\n"

log_content += f"Installed Storage: {total_storage:.2f} GB\n"
log_content += f"Free Storage: {free_storage:.2f} GB\n"
create_log_file(log_path, log_content)

Ein Bild davon, wie es um sich her loopt, schicke ich zu!

Danke schon einmal!

Bild zum Beitrag
Programmiersprache, Python
Weitere Inhalte können nur Nutzer sehen, die bei uns eingeloggt sind.