Set up Python virtual environments and dependency management
✓Works with OpenClaudeYou are a Python developer setting up isolated project environments. The user wants to create and manage Python virtual environments and handle project dependencies effectively.
What to check first
- Run
python --versionto verify Python 3.3+ is installed (venv is built-in) - Confirm your project directory exists and you can write to it
- Check if
pipis available withpip --version
Steps
- Navigate to your project directory with
cd /path/to/project - Create a virtual environment using
python -m venv venv(the secondvenvis the folder name) - Activate the venv: on Linux/Mac run
source venv/bin/activate, on Windows runvenv\Scripts\activate - Verify activation by checking the terminal prompt shows
(venv)prefix - Upgrade pip with
pip install --upgrade pip - Create a
requirements.txtfile listing your dependencies (one package per line with optional version pins) - Install all dependencies at once with
pip install -r requirements.txt - Save your current environment state anytime with
pip freeze > requirements.txt
Code
#!/usr/bin/env python3
"""
Virtual environment setup and dependency management helper.
Run this script in your project root to set up venv and install dependencies.
"""
import subprocess
import sys
import os
from pathlib import Path
def create_venv(venv_name="venv"):
"""Create a virtual environment."""
print(f"Creating virtual environment: {venv_name}")
subprocess.check_call([sys.executable, "-m", "venv", venv_name])
print(f"✓ Virtual environment created at {venv_name}/")
def get_venv_python(venv_name="venv"):
"""Return path to the venv's Python executable."""
if sys.platform == "win32":
return os.path.join(venv_name, "Scripts", "python.exe")
return os.path.join(venv_name, "bin", "python")
def install_requirements(venv_name="venv", requirements_file="requirements.txt"):
"""Install packages from requirements.txt using the venv's pip."""
venv_python = get_venv_python(venv_name)
if not Path(requirements_file).exists():
print(f"Warning: {requirements_file} not found, skipping installation")
return
print(f"Installing packages from {requirements_file}...")
subprocess.check_call([venv_python, "-m", "pip", "install", "--upgrade", "pip"])
subprocess.check_call([venv_python, "-m", "pip", "install", "-r", requirements_file])
print(f"✓ Dependencies installed")
def freeze_requirements(venv_name="venv", output_file="requirements.txt"):
"""Generate requirements.txt from installed packages
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Python Skills
Other Claude Code skills in the same category — free to download.
Django Setup
Scaffold Django project with models, views, and URLs
Flask Setup
Scaffold Flask application with blueprints and extensions
FastAPI Setup
Scaffold FastAPI with async endpoints and auto-docs
Pytest Setup
Configure pytest with fixtures, plugins, and coverage
Poetry Setup
Set up Poetry for Python dependency and package management
Python Typing
Add comprehensive type hints and mypy configuration to Python code
Django REST Framework
Set up Django REST Framework with serializers and viewsets
Python Logging
Configure structured logging for Python applications
Want a Python skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.