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
pythoncommand.
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\activate3. 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,
0is usually correct. - If you have an external USB camera, you might need to change this to
1or2indrowsiness_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.
- Check your CUDA version:
nvidia-smi - Visit pytorch.org to get the specific install command for your CUDA version.
🔍 Troubleshooting for Beginners
| Problem | Why is this happening? | How to fix it |
|---|---|---|
pip is not recognized | Python is not in your system PATH | Re-install Python and check “Add to PATH” |
cv2.error regarding camera | The camera is being used by Zoom, Teams, or another app | Close all other apps using the camera |
Out of Memory during training | Your GPU doesn’t have enough VRAM for the batch size | Change batch=8 to batch=4 in train_yolo.py |
winsound fails on Mac/Linux | winsound only works on Windows | Use a cross-platform library like playsound |
Related Components
Last Updated: 2026-05-03