Virtual Environment Setup Guide¶
Status: Informational
Scope: Virtual environment setup for the project
Last Updated: December 24, 2025 18:58:31
Created: December 8, 2025 17:09:22
π Overview¶
This project uses a leetcode Python virtual environment to isolate dependencies. Unit test scripts automatically use this virtual environment.
π§ Virtual Environment Setup¶
Windows¶
1. Create Virtual Environment¶
2. Activate Virtual Environment¶
3. Install Dependencies¶
# Install basic dependencies
pip install -r requirements.txt
# Install test dependencies
pip install pytest pytest-cov
Linux / macOS¶
1. Create Virtual Environment¶
2. Activate Virtual Environment¶
3. Install Dependencies¶
# Install basic dependencies
pip install -r requirements.txt
# Install test dependencies
pip install pytest pytest-cov
π§ͺ Running Tests¶
Method 1: Using Test Scripts (Recommended)¶
Test scripts automatically use the virtual environment:
Method 2: Manual Virtual Environment Usage¶
# Windows
leetcode\Scripts\activate
cd .dev
leetcode\..\Scripts\python.exe -m pytest tests -v
# Linux/Mac
source leetcode/bin/activate
cd .dev
python -m pytest tests -v
Method 3: Direct Virtual Environment Python Usage¶
No need to activate the virtual environment:
# Windows (from project root)
leetcode\Scripts\python.exe -m pytest .dev/tests -v
# Linux/Mac (from project root)
leetcode/bin/python -m pytest .dev/tests -v
π Verify Setup¶
Check if Virtual Environment Exists¶
Check if pytest is Installed¶
# Windows
leetcode\Scripts\python.exe -m pytest --version
# Linux/Mac
leetcode/bin/python -m pytest --version
Check Installed Packages¶
π¦ Virtual Environment Paths¶
Test scripts use the following paths:
Windows¶
- Python executable:
leetcode\Scripts\python.exe - Activation script:
leetcode\Scripts\activate.bat(CMD) orleetcode\Scripts\Activate.ps1(PowerShell)
Linux/Mac¶
- Python executable:
leetcode/bin/python - Activation script:
leetcode/bin/activate
β οΈ Common Issues¶
Q1: Virtual Environment Not Found¶
Error Message:
Solution:
# Create virtual environment
python -m venv leetcode
# Activate and install dependencies
leetcode\Scripts\activate
pip install -r requirements.txt
pip install pytest pytest-cov
Q2: pytest Not Installed¶
Error Message:
Solution:
# Activate virtual environment
leetcode\Scripts\activate # Windows
source leetcode/bin/activate # Linux/Mac
# Install pytest
pip install pytest pytest-cov
Q3: Module 'runner' Not Found¶
Error Message:
Solution: Ensure you run tests from the project root directory, or use the test scripts.
π Updating Dependencies¶
Update Test Dependencies¶
# Activate virtual environment
leetcode\Scripts\activate # Windows
source leetcode/bin/activate # Linux/Mac
# Update packages
pip install --upgrade pytest pytest-cov
Update All Dependencies¶
# Activate virtual environment
leetcode\Scripts\activate # Windows
source leetcode/bin/activate # Linux/Mac
# Update all packages
pip install --upgrade -r requirements.txt
π requirements.txt¶
Ensure requirements.txt includes test dependencies:
# LeetCode Practice Framework - Dependencies
# Required packages:
debugpy>=1.8.0 # Debug support for VS Code
# Testing packages:
pytest>=7.4.0 # Unit testing framework
pytest-cov>=4.1.0 # Coverage reporting
# Optional packages (for complexity estimation):
big-O>=0.10.0 # Time complexity estimation
# Documentation generation (MkDocs):
mkdocs>=1.6.0 # MkDocs static site generator
mkdocs-material>=9.5.0 # Material theme for MkDocs
mkdocs-minify-plugin>=0.7.0 # Minify HTML output
mkdocs-include-markdown-plugin>=7.0.0 # Include markdown files
π― Best Practices¶
- Use Virtual Environment: Always install dependencies in the virtual environment
- Use Test Scripts: Test scripts automatically handle the virtual environment
- Regular Updates: Regularly update dependencies to get the latest features and fixes
- Version Control: Do not add the
leetcode/folder to Git
π Need Help?¶
If you have questions, please refer to: - Contributors README - Maintainer Guide - Testing Documentation - Complete Testing Documentation - Project main README.md - Python Environment section
Test Maintainer: luffdev
Created Date: 2025-12-08