-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
148 lines (125 loc) · 4.56 KB
/
setup.py
File metadata and controls
148 lines (125 loc) · 4.56 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
146
147
148
#!/usr/bin/env python3
"""
Setup script for the Sentiment Analysis Project
This script automates the setup process for new users.
"""
import os
import sys
import subprocess
import platform
def run_command(command, description):
"""Run a command and handle errors"""
print(f"🔄 {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"❌ Error during {description}: {e}")
print(f"Error output: {e.stderr}")
return False
def check_python_version():
"""Check if Python version is compatible"""
version = sys.version_info
if version.major < 3 or (version.major == 3 and version.minor < 8):
print("❌ Python 3.8 or higher is required")
print(f"Current version: {version.major}.{version.minor}.{version.micro}")
return False
print(f"✅ Python {version.major}.{version.minor}.{version.micro} is compatible")
return True
def create_virtual_environment():
"""Create and activate virtual environment"""
if os.path.exists("venv"):
print("✅ Virtual environment already exists")
return True
return run_command("python -m venv venv", "Creating virtual environment")
def install_dependencies():
"""Install required dependencies"""
# Determine the correct pip path
if platform.system() == "Windows":
pip_path = "venv\\Scripts\\pip"
else:
pip_path = "venv/bin/pip"
commands = [
(f"{pip_path} install --upgrade pip", "Upgrading pip"),
(f"{pip_path} install -r requirements.txt", "Installing dependencies")
]
for command, description in commands:
if not run_command(command, description):
return False
return True
def download_nltk_data():
"""Download required NLTK data"""
nltk_script = """
import nltk
import ssl
try:
_create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
pass
else:
ssl._create_default_https_context = _create_unverified_https_context
nltk.download('punkt')
nltk.download('stopwords')
nltk.download('vader_lexicon')
print("NLTK data downloaded successfully")
"""
# Determine the correct python path
if platform.system() == "Windows":
python_path = "venv\\Scripts\\python"
else:
python_path = "venv/bin/python"
return run_command(f'{python_path} -c "{nltk_script}"', "Downloading NLTK data")
def create_sample_data():
"""Create sample data directory and file if it doesn't exist"""
if not os.path.exists("data"):
os.makedirs("data")
print("✅ Created data directory")
sample_data_path = "data/sample_data.csv"
if not os.path.exists(sample_data_path):
sample_data = """datetime,product,quote
2024-01-15 10:30:00,Product A,"This product is amazing and works perfectly!"
2024-01-15 11:45:00,Product B,"I'm not satisfied with the quality."
2024-01-16 09:15:00,Product A,"Great customer service and fast delivery."
2024-01-16 14:20:00,Product C,"The interface is confusing and hard to use."
2024-01-17 16:30:00,Product B,"Excellent value for money, highly recommended!"
"""
with open(sample_data_path, "w") as f:
f.write(sample_data)
print("✅ Created sample data file")
def main():
"""Main setup function"""
print("🚀 Setting up Sentiment Analysis Project...")
print("=" * 50)
# 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 install_dependencies():
print("❌ Failed to install dependencies")
sys.exit(1)
# Download NLTK data
if not download_nltk_data():
print("❌ Failed to download NLTK data")
sys.exit(1)
# Create sample data
create_sample_data()
print("\n" + "=" * 50)
print("🎉 Setup completed successfully!")
print("\nNext steps:")
print("1. Activate the virtual environment:")
if platform.system() == "Windows":
print(" venv\\Scripts\\activate")
else:
print(" source venv/bin/activate")
print("2. Run the analysis:")
print(" python src/main.py")
print("3. Or explore with Jupyter:")
print(" jupyter lab")
print("\nFor more information, see README.md")
if __name__ == "__main__":
main()