File size: 1,557 Bytes
d828ce4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 subprocess
import sys
import venv
from pathlib import Path

def setup_project():
    # Ensure we're in the right directory
    project_dir = Path(__file__).parent.absolute()
    os.chdir(project_dir)

    print("Setting up the project...")

    # Create virtual environment if it doesn't exist
    venv_dir = project_dir / "myenv"
    if not venv_dir.exists():
        print("Creating virtual environment...")
        venv.create(venv_dir, with_pip=True)

    # Determine the path to the Python executable in the virtual environment
    if sys.platform == "win32":
        python_executable = venv_dir / "Scripts" / "python.exe"
        pip_executable = venv_dir / "Scripts" / "pip.exe"
    else:
        python_executable = venv_dir / "bin" / "python"
        pip_executable = venv_dir / "bin" / "pip"

    # Upgrade pip
    print("Upgrading pip...")
    subprocess.run([str(python_executable), "-m", "pip", "install", "--upgrade", "pip"])

    # Install requirements
    print("Installing requirements...")
    requirements_file = project_dir / "requirements.txt"
    if requirements_file.exists():
        subprocess.run([str(pip_executable), "install", "-r", "requirements.txt"])
    else:
        print("Warning: requirements.txt not found!")

    print("\nSetup completed successfully!")
    print("\nTo activate the virtual environment:")
    if sys.platform == "win32":
        print(f"    {venv_dir}\\Scripts\\activate")
    else:
        print(f"    source {venv_dir}/bin/activate")

if __name__ == "__main__":
    setup_project()