-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_python_env.py
More file actions
145 lines (121 loc) Β· 4.37 KB
/
Copy pathsetup_python_env.py
File metadata and controls
145 lines (121 loc) Β· 4.37 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env python3
"""
Setup script for DataIntel Hub Backend - Python Environment
This script helps set up the Python environment for FastAPI
"""
import subprocess
import sys
import os
from pathlib import Path
def run_command(command, description):
"""Run a command and handle errors"""
print(f"\nπ {description}...")
try:
result = subprocess.run(command, shell=True, check=True, capture_output=True, text=True)
print(f"β
{description} completed successfully")
return True
except subprocess.CalledProcessError as e:
print(f"β {description} failed:")
print(f"Error: {e.stderr}")
return False
def check_python_version():
"""Check if Python version is compatible"""
print("π Checking Python version...")
version = sys.version_info
if version.major < 3 or (version.major == 3 and version.minor < 8):
print(f"β Python {version.major}.{version.minor} is not supported. Please use Python 3.8 or higher.")
return False
print(f"β
Python {version.major}.{version.minor}.{version.micro} is compatible")
return True
def create_virtual_environment():
"""Create a virtual environment"""
venv_path = Path("venv")
if venv_path.exists():
print("β
Virtual environment already exists")
return True
return run_command("python -m venv venv", "Creating virtual environment")
def activate_virtual_environment():
"""Activate virtual environment and install dependencies"""
if os.name == 'nt': # Windows
activate_cmd = "venv\\Scripts\\activate"
pip_cmd = "venv\\Scripts\\pip"
else: # Unix/Linux/Mac
activate_cmd = "source venv/bin/activate"
pip_cmd = "venv/bin/pip"
# Install dependencies
success = run_command(f"{pip_cmd} install --upgrade pip", "Upgrading pip")
if not success:
return False
success = run_command(f"{pip_cmd} install -r requirements.txt", "Installing dependencies")
return success
def create_env_file():
"""Create .env file if it doesn't exist"""
env_file = Path(".env")
if env_file.exists():
print("β
.env file already exists")
return True
print("π Creating .env file...")
env_content = """# Database Configuration
DATABASE_URL=mongodb://localhost:27017/dataintel_hub
# JWT Configuration
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
# Email Configuration
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=your-email@gmail.com
SMTP_PASS=your-app-password
# AWS Configuration
AWS_ACCESS_KEY_ID=your-aws-access-key
AWS_SECRET_ACCESS_KEY=your-aws-secret-key
AWS_REGION=us-east-1
AWS_BUCKET_NAME=your-bucket-name
# OpenAI Configuration (for CrewAI)
OPENAI_API_KEY=your-openai-api-key
# Server Configuration
PORT=8000
NODE_ENV=development
"""
try:
with open(env_file, 'w') as f:
f.write(env_content)
print("β
.env file created successfully")
print("β οΈ Please update the .env file with your actual configuration values")
return True
except Exception as e:
print(f"β Failed to create .env file: {e}")
return False
def main():
"""Main setup function"""
print("π Setting up DataIntel Hub Backend - Python Environment")
print("=" * 60)
# Check Python version
if not check_python_version():
sys.exit(1)
# Create virtual environment
if not create_virtual_environment():
print("β Failed to create virtual environment")
sys.exit(1)
# Install dependencies
if not activate_virtual_environment():
print("β Failed to install dependencies")
sys.exit(1)
# Create .env file
create_env_file()
print("\n" + "=" * 60)
print("π Setup completed successfully!")
print("\nπ Next steps:")
print("1. Activate the virtual environment:")
if os.name == 'nt': # Windows
print(" venv\\Scripts\\activate")
else: # Unix/Linux/Mac
print(" source venv/bin/activate")
print("2. Update the .env file with your configuration")
print("3. Run the FastAPI server:")
print(" python main.py")
print(" or")
print(" uvicorn main:app --reload")
print("\nπ API documentation will be available at:")
print(" http://localhost:8000/docs")
print(" http://localhost:8000/redoc")
if __name__ == "__main__":
main()