$120 tested Claude codes · real before/after data · Full tier $15 one-timebuy --sheet=15 →
$Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. download --free →
clskills.sh — terminal v2.4 — 2,347 skills indexed● online
[CL]Skills_
PythonbeginnerNew

Python Venv

Share

Set up Python virtual environments and dependency management

Works with OpenClaude

You 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 --version to verify Python 3.3+ is installed (venv is built-in)
  • Confirm your project directory exists and you can write to it
  • Check if pip is available with pip --version

Steps

  1. Navigate to your project directory with cd /path/to/project
  2. Create a virtual environment using python -m venv venv (the second venv is the folder name)
  3. Activate the venv: on Linux/Mac run source venv/bin/activate, on Windows run venv\Scripts\activate
  4. Verify activation by checking the terminal prompt shows (venv) prefix
  5. Upgrade pip with pip install --upgrade pip
  6. Create a requirements.txt file listing your dependencies (one package per line with optional version pins)
  7. Install all dependencies at once with pip install -r requirements.txt
  8. 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

Quick Info

CategoryPython
Difficultybeginner
Version1.0.0
AuthorClaude Skills Hub
pythonvenvdependencies

Install command:

curl -o ~/.claude/skills/python-venv.md https://claude-skills-hub.vercel.app/skills/python/python-venv.md

Related Python Skills

Other Claude Code skills in the same category — free to download.

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.