-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
75 lines (62 loc) · 2.2 KB
/
run.py
File metadata and controls
75 lines (62 loc) · 2.2 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
"""
run.py - Entry point that ensures the app is launched with the correct Python (3.11).
Usage:
python run.py
py -3.11 run.py
"""
import sys
import shutil
import subprocess
REQUIRED_MAJOR = 3
REQUIRED_MINOR = 11
def _is_target_python(version_output: str) -> bool:
return f"Python {REQUIRED_MAJOR}.{REQUIRED_MINOR}" in version_output
def _find_python_311_cmd():
"""Return a command prefix that launches Python 3.11, or None if unavailable."""
candidates = [
["py", f"-{REQUIRED_MAJOR}.{REQUIRED_MINOR}"],
["python3.11"],
["python"],
]
for cmd_prefix in candidates:
exe = shutil.which(cmd_prefix[0])
if not exe:
continue
try:
result = subprocess.run(
cmd_prefix + ["--version"],
capture_output=True,
text=True,
check=False,
)
version_text = (result.stdout or "") + (result.stderr or "")
if _is_target_python(version_text):
return cmd_prefix
except Exception:
continue
return None
def main():
major = sys.version_info.major
minor = sys.version_info.minor
if major != REQUIRED_MAJOR or minor < REQUIRED_MINOR:
# Try to re-launch using a discovered Python 3.11 interpreter
py311 = _find_python_311_cmd()
if py311 is None:
print(
f"ERROR: Python {REQUIRED_MAJOR}.{REQUIRED_MINOR} not found.\n"
f"Currently running: Python {major}.{minor}\n"
f"PyCaret and Lale require Python 3.11 with the correct scikit-learn version.\n"
f"Please run:\n"
f" py -3.11 -m streamlit run app.py"
)
sys.exit(1)
print(f"Re-launching with Python {REQUIRED_MAJOR}.{REQUIRED_MINOR}...")
cmd = py311 + ["-m", "streamlit", "run", "app.py"] + sys.argv[1:]
raise SystemExit(subprocess.call(cmd))
else:
# We are already in the correct interpreter, just start streamlit
import streamlit.web.cli as stcli
sys.argv = ["streamlit", "run", "app.py"] + sys.argv[1:]
sys.exit(stcli.main())
if __name__ == "__main__":
main()