Bugfix: Virtuelle Umgebung jetzt vollständig aktivierbar inkl. Neustart mit Fenster (Windows). Wrapper prüft .venv korrekt.

This commit is contained in:
Adam Skotarczak 2025-04-22 09:01:23 +02:00
parent f7fc11d01c
commit d12dd37673
4 changed files with 47 additions and 15 deletions

View File

@ -2,10 +2,16 @@
## pyUpload (TKInter-Version 1.0)
- **2025-04-22 - v.1.0.2**
- Behoben
-- Wrapper-Skript `start.py` erkennt nun fehlende `.venv` und startet `main.py` beim Erststart korrekt mit System-Python, danach mit venv (`start.py`).
-- `main.py` verwendet unter Windows statt `os.execv()` nun `subprocess.Popen(..., CREATE_NEW_CONSOLE)` für einen sauberen Neustart mit sichtbarer Konsole (`main.py`).
- Entfernt
-- Nicht mehr benötigte Funktion `activate_venv()` entfernt (`main.py`).
- 2025-04-21
- **2025-04-21 - v.1.0.1**
- Geändert
- `main.py` übernimmt nun automatisch die Erstellung der virtuellen Umgebung `.venv` und die Installation der Abhängigkeiten aus `requirements.txt`
@ -26,3 +32,6 @@
- PowerShell-Inkompatibilitäten mit `set /p` entfernt
- `.cmd`-Startskripte reagieren jetzt korrekt auf STRG+C
- Mehrere Markdown-Korrekturen (Codeblöcke, Leerzeilen, Lesbarkeit)
- **2025-04-21 - v.1.0.0**
- release!

View File

@ -1 +1 @@
1.0.1
1.0.2

View File

@ -2,7 +2,9 @@
# © 2025 Adam Skotarczak (adam@skotarczak.net)
# Dieses Softwarepaket darf nicht ohne Genehmigung weiterverbreitet werden!
# Version 1.0.0 (12.03.2025)
#
# Version 1.0.2 (22.04.2025 - virtuelle Umgebung korrekt aktiviert)
# Manuel in z.B VS-Code: .\app\.venv\Scripts\activate
import os
import sys
@ -16,17 +18,27 @@ VENV_DIR = os.path.join(BASE_DIR, ".venv")
VENV_PYTHON = os.path.join(VENV_DIR, "Scripts", "python.exe") if os.name == "nt" else os.path.join(VENV_DIR, "bin", "python")
REQUIREMENTS_FILE = os.path.join(BASE_DIR, "requirements.txt")
# Wenn wir NICHT in der venv sind → prüfen, ob venv existiert
if sys.prefix == sys.base_prefix and not os.path.exists(VENV_DIR):
print("[Setup] Virtuelle Umgebung wird erstellt...")
subprocess.run([sys.executable, "-m", "venv", "--copies", VENV_DIR], check=True)
# Wenn wir NICHT in der venv sind
if sys.prefix == sys.base_prefix:
# venv erstellen falls nötig
if not os.path.exists(VENV_DIR):
print("[Setup] Virtuelle Umgebung wird erstellt...")
subprocess.run([sys.executable, "-m", "venv", "--copies", VENV_DIR], check=True)
print("[Setup] requirements.txt wird installiert...")
subprocess.run([VENV_PYTHON, "-m", "pip", "install", "--upgrade", "pip"], check=True)
subprocess.run([VENV_PYTHON, "-m", "pip", "install", "-r", REQUIREMENTS_FILE], check=True)
print("[Setup] requirements.txt wird installiert...")
subprocess.run([VENV_PYTHON, "-m", "pip", "install", "--upgrade", "pip"], check=True)
subprocess.run([VENV_PYTHON, "-m", "pip", "install", "-r", REQUIREMENTS_FILE], check=True)
# unabhängig davon: Neustart innerhalb der venv
print("[Setup] Starte erneut mit aktivierter Umgebung...")
os.execv(VENV_PYTHON, [VENV_PYTHON] + sys.argv)
if os.name == "nt":
subprocess.Popen([VENV_PYTHON] + sys.argv, creationflags=subprocess.CREATE_NEW_CONSOLE)
else:
os.execv(VENV_PYTHON, [VENV_PYTHON] + sys.argv)
sys.exit(0)
#os.execv(VENV_PYTHON, [VENV_PYTHON] + sys.argv)
# Wir sind jetzt sicher in der richtigen Umgebung → Rest des Programms geht hier weiter:
@ -60,8 +72,6 @@ def activate_venv():
print(f"FEHLER: Virtuelle Umgebung nicht gefunden ({VENV_DIR}). Bitte zuerst install.cmd ausführen.")
sys.exit(1)
activate_venv()
# -------------------------------------------------------------------
# Globale Konfigurationen & Logging
# -------------------------------------------------------------------

View File

@ -1,3 +1,16 @@
import subprocess, os
#!/usr/bin/env python3
import os
import sys
import subprocess
os.chdir(os.path.dirname(__file__))
subprocess.run(["python", "app/main.py"])
# Zielpfad zur venv-Python
venv_python = os.path.join("app", ".venv", "Scripts", "python.exe") if os.name == "nt" else os.path.join("app", ".venv", "bin", "python")
# Verwende venv-Python, wenn vorhanden sonst system-Python für initialen Aufbau
python_exec = venv_python if os.path.exists(venv_python) else sys.executable
# Starte main.py
subprocess.run([python_exec, "app/main.py"] + sys.argv[1:])