Environment & Installation

Setting up an AI project can be intimidating due to the number of dependencies. This guide breaks down exactly what you need and why you need it.

🏗️ System Dependencies

Before installing the project, you need to understand the “Dependency Tree.” Each library provides a specific capability to the system.

graph TD
    Project[Drowsiness Detector] --> CV[Computer Vision]
    Project --> AI[Deep Learning]
    Project --> OS[System Integration]
    
    CV --> OpenCV[OpenCV: Image Processing & Camera]
    AI --> Torch[PyTorch: Tensor Math]
    AI --> Ultralytics[Ultralytics: YOLOv11 Model]
    OS --> Plyer[Plyer: Desktop Notifications]
    OS --> WinSound[WinSound: Audio Alarms]

🚀 Step-by-Step Setup

1. Python Installation

Ensure you have Python 3.8 or higher.

  • Tip: When installing Python on Windows, make sure to check the box “Add Python to PATH”. If you don’t, your terminal won’t recognize the python command.

2. The Virtual Environment (The “Safety Box”)

We use a virtual environment (venv) to keep the project’s libraries separate from your other Python projects. This prevents “Dependency Hell” where updating one project breaks another.

# Create the environment
python -m venv venv
 
# Activate it (Windows)
.\venv\Scripts\activate

3. Installing the Brains

Run the following command to install everything listed in requirements.txt:

pip install -r requirements.txt

🛠️ Hardware Setup

Webcam Configuration

The system uses cv2.VideoCapture(0).

  • If you have an integrated webcam, 0 is usually correct.
  • If you have an external USB camera, you might need to change this to 1 or 2 in drowsiness_detection.py.

GPU Acceleration (Optional)

If you have an NVIDIA GPU, you can make the system significantly faster by installing the CUDA-enabled version of PyTorch.

  1. Check your CUDA version: nvidia-smi
  2. Visit pytorch.org to get the specific install command for your CUDA version.

🔍 Troubleshooting for Beginners

ProblemWhy is this happening?How to fix it
pip is not recognizedPython is not in your system PATHRe-install Python and check “Add to PATH”
cv2.error regarding cameraThe camera is being used by Zoom, Teams, or another appClose all other apps using the camera
Out of Memory during trainingYour GPU doesn’t have enough VRAM for the batch sizeChange batch=8 to batch=4 in train_yolo.py
winsound fails on Mac/Linuxwinsound only works on WindowsUse a cross-platform library like playsound

Last Updated: 2026-05-03