-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
89 lines (77 loc) · 2.62 KB
/
setup.py
File metadata and controls
89 lines (77 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
"""
setup.py — one-time installer for RL Gridworld App
Run this once before launching rl_gridworld_app.py
python setup.py
"""
import sys
import subprocess
import importlib
import platform
REQUIRED = {
"numpy": "numpy",
"matplotlib": "matplotlib",
}
def check_python_version():
major, minor = sys.version_info[:2]
if (major, minor) < (3, 8):
print(f" ✗ Python 3.8+ required (you have {major}.{minor})")
sys.exit(1)
print(f" ✓ Python {major}.{minor} detected")
def check_tkinter():
try:
import tkinter # noqa: F401
print(" ✓ tkinter is available")
return True
except ImportError:
print(" ✗ tkinter not found")
os_name = platform.system()
if os_name == "Linux":
print(" Fix: sudo apt install python3-tk (Debian/Ubuntu)")
print(" sudo dnf install python3-tkinter (Fedora/RHEL)")
elif os_name == "Darwin":
print(" Fix: reinstall Python from https://python.org")
print(" (the official installer ships with tkinter)")
elif os_name == "Windows":
print(" Fix: re-run the Python installer, tick 'tcl/tk and IDLE'")
return False
def install_packages():
all_ok = True
for import_name, pip_name in REQUIRED.items():
try:
importlib.import_module(import_name)
print(f" ✓ {pip_name} already installed")
except ImportError:
print(f" ↓ Installing {pip_name} …", end="", flush=True)
result = subprocess.run(
[sys.executable, "-m", "pip", "install", pip_name],
capture_output=True, text=True
)
if result.returncode == 0:
print(" done")
else:
print(" FAILED")
print(result.stderr.strip())
all_ok = False
return all_ok
def main():
print("=" * 50)
print(" RL Gridworld App — Setup")
print("=" * 50)
print("\n[1] Checking Python version …")
check_python_version()
print("\n[2] Checking tkinter …")
tk_ok = check_tkinter()
print("\n[3] Installing Python packages …")
pkgs_ok = install_packages()
print("\n" + "=" * 50)
if pkgs_ok and tk_ok:
print(" All dependencies ready.")
print(" Launch the app with:")
print()
print(" python rl_gridworld_app.py")
else:
print(" Some issues were found — see messages above.")
print(" Fix them, then re-run this script.")
print("=" * 50)
if __name__ == "__main__":
main()