Enforce virtual environment usage for Python projects that require third-party packages.
Works with: OpenCode, Claude Code, Cursor, Cline, and other AI coding assistants.
- ✅ Require venv when installing packages or using third-party dependencies
- ✅ Reuse existing virtual environment (
.venv,venv,env,.env) - ✅ Auto-create if not exists
- ✅ Support
uv(recommended) with fallback to standardvenv - ✅ Support Conda/Mamba environments
- ✅ Cross-platform (Linux, macOS, Windows)
- ✅ Skip venv for simple stdlib-only commands
| Scenario | Required? |
|---|---|
pip install / uv pip install |
✅ YES |
| Running scripts with third-party imports | ✅ YES |
Projects with requirements.txt / pyproject.toml |
✅ YES |
| Scenario | Example |
|---|---|
| Simple stdlib one-liner | python3 -c "print('hello')" |
| Built-in modules only | python3 -c "import json; ..." |
| Version check | python3 --version |
cd ~/.config/opencode/skills
git clone https://github.com/cikichen/skill-python-venv.git python-venvcd ~/.claude/skills
git clone https://github.com/cikichen/skill-python-venv.git python-venvCopy SKILL.md to your assistant's custom instructions or skills directory.
# Reuse existing or create new (with uv fallback to venv)
[ -d .venv ] && source .venv/bin/activate || { command -v uv &>/dev/null && uv venv || python3 -m venv .venv; source .venv/bin/activate; }if (Test-Path .venv) { .\.venv\Scripts\Activate.ps1 }
elseif (Get-Command uv -ErrorAction SilentlyContinue) { uv venv; .\.venv\Scripts\Activate.ps1 }
else { python -m venv .venv; .\.venv\Scripts\Activate.ps1 }| File | Install Command |
|---|---|
requirements.txt |
pip install -r requirements.txt |
pyproject.toml |
pip install -e . |
pyproject.toml + poetry.lock |
poetry install |
pyproject.toml + uv.lock |
uv sync |
environment.yml |
conda env create -f environment.yml |
MIT