File size: 1,407 Bytes
69c20e8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import sys
import subprocess
import platform

def main():
    print(f"OS Detected: {platform.system()}")
    
    # Define venv directory
    venv_dir = "venv"
    
    # Create venv
    print(f"Creating virtual environment in '{venv_dir}'...")
    try:
        subprocess.check_call([sys.executable, "-m", "venv", venv_dir])
    except subprocess.CalledProcessError as e:
        print(f"Error creating venv: {e}")
        sys.exit(1)
        
    # Determine pip path based on OS
    if platform.system() == "Windows":
        pip_exe = os.path.join(venv_dir, "Scripts", "pip")
    else:
        pip_exe = os.path.join(venv_dir, "bin", "pip")
        
    # Upgrade pip
    print("Upgrading pip...")
    try:
        subprocess.check_call([pip_exe, "install", "--upgrade", "pip"])
    except subprocess.CalledProcessError as e:
        print(f"Error upgrading pip: {e}")
        
    # Install dependencies
    if os.path.exists("requirements.txt"):
        print("Installing dependencies from requirements.txt...")
        try:
            subprocess.check_call([pip_exe, "install", "-r", "requirements.txt"])
        except subprocess.CalledProcessError as e:
            print(f"Error installing dependencies: {e}")
            sys.exit(1)
    else:
        print("requirements.txt not found.")
        
    print("Setup Complete! Run the server now.")

if __name__ == "__main__":
    main()