Repository navigation
Expand file tree
/
Copy pathSetup.py
More file actions
85 lines (72 loc) · 2.65 KB
/
Copy pathSetup.py
File metadata and controls
85 lines (72 loc) · 2.65 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
import os
import sys
import subprocess
import venv
from pathlib import Path
def create_virtual_environment():
"""Create a virtual environment for the application."""
venv_path = Path("venv")
if not venv_path.exists():
print("Creating virtual environment...")
venv.create(venv_path, with_pip=True)
return True
return False
def get_python_path():
"""Get the path to the Python executable in the virtual environment."""
if sys.platform == "win32":
return str(Path("venv/Scripts/python.exe"))
return str(Path("venv/bin/python"))
def install_requirements():
"""Install required packages from requirements.txt."""
python_path = get_python_path()
# Ensure pip is up to date
subprocess.run([python_path, "-m", "pip", "install", "--upgrade", "pip"], check=True)
# Install requirements from file
requirements_path = Path("requirements.txt")
if requirements_path.exists():
print("Installing requirements from requirements.txt...")
subprocess.run([python_path, "-m", "pip", "install", "-r", str(requirements_path)], check=True)
else:
print("Warning: requirements.txt not found!")
def create_launcher():
"""Create launcher scripts for different platforms."""
if sys.platform == "win32":
# Windows batch file
launcher_content = """@echo off
call venv\\Scripts\\activate
python model_library_gui.py
pause"""
with open("run_model_library.bat", "w") as f:
f.write(launcher_content)
else:
# Unix shell script
launcher_content = """#!/bin/bash
source venv/bin/activate
python model_library_gui.py"""
launcher_path = Path("run_model_library.sh")
with open(launcher_path, "w") as f:
f.write(launcher_content)
# Make the shell script executable
launcher_path.chmod(0o755)
def main():
try:
# Create virtual environment if it doesn't exist
if create_virtual_environment():
print("Virtual environment created successfully.")
else:
print("Virtual environment already exists.")
# Install or update requirements
install_requirements()
# Create launcher script
create_launcher()
print("\nSetup complete!")
if sys.platform == "win32":
print("You can now run the application using run_model_library.bat")
else:
print("You can now run the application using ./run_model_library.sh")
except Exception as e:
print(f"Error during setup: {str(e)}")
return 1
return 0
if __name__ == "__main__":
sys.exit(main())