4.9 KiB
MOTM Application - Virtual Environment Setup Guide
This guide will help you set up a Python virtual environment for the MOTM Flask application.
Prerequisites
- Python 3.7 or higher must be installed on your system
- pip package manager should be available
Quick Setup (Windows)
Step 1: Check Python Installation
Open Command Prompt or PowerShell and run:
python --version
If Python is not found, you may need to:
- Install Python from python.org
- Or use
pycommand if you have Python Launcher installed
Step 2: Create Virtual Environment
Navigate to the motm_app directory and run:
Option A: Using python command
python -m venv venv
Option B: Using py command (if available)
py -m venv venv
Option C: Using full path (if needed)
C:\Python39\python.exe -m venv venv
Step 3: Activate Virtual Environment
Windows Command Prompt:
venv\Scripts\activate.bat
Windows PowerShell:
venv\Scripts\Activate.ps1
Step 4: Install Dependencies
With the virtual environment activated:
pip install --upgrade pip
pip install -r requirements.txt
Step 5: Run the Application
python main.py
The application will be available at: http://localhost:5000
Quick Setup (Unix/Linux/Mac)
Step 1: Create Virtual Environment
python3 -m venv venv
Step 2: Activate Virtual Environment
source venv/bin/activate
Step 3: Install Dependencies
pip install --upgrade pip
pip install -r requirements.txt
Step 4: Run the Application
python main.py
Using the Convenience Scripts
After setting up the virtual environment, you can use the provided scripts:
Windows
- Setup:
setup_venv_windows.bat - Activate:
activate_motm.bat - Run:
run_motm.bat
Unix/Linux/Mac
- Activate:
source activate_motm.sh - Run:
./run_motm.sh
Troubleshooting
Python Not Found
Windows:
- Install Python from python.org
- During installation, check "Add Python to PATH"
- Restart your command prompt
Alternative for Windows:
- Install Python from Microsoft Store
- Use
pycommand instead ofpython
Virtual Environment Issues
Permission Errors (Windows):
# Try running as Administrator
# Or use PowerShell with execution policy
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Virtual Environment Already Exists:
# Remove existing environment
rmdir /s venv
# Or on Unix/Linux/Mac
rm -rf venv
Dependencies Not Installing
- Activate virtual environment first
- Upgrade pip:
pip install --upgrade pip - Install individually:
pip install Flask - Check internet connection
- Try using --user flag:
pip install --user -r requirements.txt
Application Not Starting
- Check virtual environment is activated (should see
(venv)in prompt) - Verify all dependencies installed:
pip list - Check for import errors:
python -c "import flask" - Review error messages in console output
Development Workflow
Daily Usage
- Activate environment:
venv\Scripts\activate.bat(Windows) orsource venv/bin/activate(Unix) - Make changes to your code
- Test application:
python main.py - Deactivate when done:
deactivate
Adding New Packages
- Activate environment
- Install package:
pip install new-package - Update requirements:
pip freeze > requirements.txt - Commit changes to version control
Updating Dependencies
- Activate environment
- Update packages:
pip install --upgrade package-name - Update requirements:
pip freeze > requirements.txt
Environment Variables
If you need to set environment variables for the application:
Windows:
set DATABASE_URL=your_database_url
python main.py
Unix/Linux/Mac:
export DATABASE_URL=your_database_url
python main.py
Database Configuration
Make sure to update db_config.py with your database connection details before running the application.
Getting Help
If you encounter issues:
- Check Python version: Should be 3.7 or higher
- Verify virtual environment: Should be activated
- Check dependencies: Run
pip listto see installed packages - Review error messages: Look for specific error details
- Test imports:
python -c "import flask, pymysql"
Production Deployment
For production deployment:
- Use same Python version as development
- Install exact dependencies:
pip install -r requirements.txt - Set environment variables for production database
- Configure web server (nginx, Apache, etc.)
- Use process manager (systemd, supervisor, etc.)
Note: This application requires access to the existing hockey results database. Ensure proper database connectivity before running.