File size: 3,675 Bytes
338d95d |
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 |
#!/usr/bin/env python3
"""
Environment setup script for CompI project.
Run this script to check and install dependencies.
"""
import subprocess
import sys
import os
from pathlib import Path
def run_command(command, description):
"""Run a shell 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."""
version = sys.version_info
if version.major == 3 and version.minor >= 8:
print(f"β
Python {version.major}.{version.minor}.{version.micro} is compatible")
return True
else:
print(f"β Python {version.major}.{version.minor}.{version.micro} is not compatible")
print("Please use Python 3.8 or higher")
return False
def check_gpu():
"""Check for CUDA availability."""
try:
import torch
if torch.cuda.is_available():
gpu_count = torch.cuda.device_count()
gpu_name = torch.cuda.get_device_name(0)
print(f"β
CUDA available with {gpu_count} GPU(s): {gpu_name}")
return True
else:
print("β οΈ CUDA not available, will use CPU")
return False
except ImportError:
print("β οΈ PyTorch not installed yet, GPU check will be done after installation")
return False
def install_requirements():
"""Install requirements from requirements.txt."""
if not Path("requirements.txt").exists():
print("β requirements.txt not found")
return False
return run_command(
f"{sys.executable} -m pip install -r requirements.txt",
"Installing requirements"
)
def download_nltk_data():
"""Download required NLTK data."""
try:
import nltk
print("\nπ Downloading NLTK data...")
nltk.download('punkt', quiet=True)
nltk.download('vader_lexicon', quiet=True)
nltk.download('stopwords', quiet=True)
print("β
NLTK data downloaded")
return True
except ImportError:
print("β οΈ NLTK not installed, skipping data download")
return False
def setup_textblob():
"""Setup TextBlob corpora."""
try:
import textblob
print("\nπ Setting up TextBlob...")
run_command(f"{sys.executable} -m textblob.download_corpora",
"Downloading TextBlob corpora")
return True
except ImportError:
print("β οΈ TextBlob not installed, skipping setup")
return False
def main():
"""Main setup function."""
print("π Setting up CompI Development Environment")
print("=" * 50)
# Check Python version
if not check_python_version():
sys.exit(1)
# Install requirements
if not install_requirements():
print("β Failed to install requirements")
sys.exit(1)
# Check GPU after PyTorch installation
check_gpu()
# Setup additional components
download_nltk_data()
setup_textblob()
print("\n" + "=" * 50)
print("π Environment setup completed!")
print("\nNext steps:")
print("1. Run: python src/test_setup.py")
print("2. Start experimenting with notebooks/")
print("3. Check out the README.md for usage examples")
if __name__ == "__main__":
main()
|