100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

Python Virtual Environments & pip Cheat Sheet

Python Virtual Environments & pip Cheat Sheet

Covers creating and activating virtual environments with venv, installing and pinning packages with pip, and managing requirements files.

1 PageBeginnerApr 5, 2026

Creating & Activating a venv

Create isolated Python environments with the built-in venv module.

bash
python3 -m venv .venv          # Create virtual environmentsource .venv/bin/activate      # Activate (macOS/Linux).venv\Scripts\activate         # Activate (Windows cmd).venv\Scripts\Activate.ps1     # Activate (Windows PowerShell)deactivate                     # Exit the virtual environmentwhich python                   # Confirm interpreter path (should point to .venv)

Installing & Managing Packages

Core pip commands for installing, upgrading, and removing packages.

bash
pip install requests             # Install latest versionpip install requests==2.31.0     # Install exact versionpip install "requests>=2.28,<3"  # Install with version rangepip install -U requests          # Upgrade to latestpip uninstall requests           # Remove a packagepip list                         # List installed packagespip show requests                # Show package detailspip list --outdated              # Show packages with newer versions available

requirements.txt Workflow

Freeze and restore dependencies for reproducible environments.

bash
pip freeze > requirements.txt              # Snapshot installed packagespip install -r requirements.txt            # Install from filepip install -r requirements-dev.txt        # Install dev-only extraspip install --upgrade -r requirements.txt  # Upgrade all pinned packages

Useful pip Flags

Handy flags for common pip workflows.

  • -e .- Install the current directory in editable/development mode (uses setup.py or pyproject.toml)
  • --no-cache-dir- Skip pip's package cache, useful in Docker builds to reduce image size
  • --index-url- Install from a custom package index instead of PyPI
  • --no-deps- Install a package without pulling in its dependencies
  • -r <file>- Install packages listed in a requirements file
  • pip check- Verify installed packages have compatible dependency versions
  • pip cache purge- Clear pip's local wheel/package cache
Pro Tip

Commit a lockfile-style requirements.txt (or use pip-tools/Poetry) so teammates and CI get identical dependency versions — plain 'pip freeze' output mixes direct and transitive dependencies, which pip-compile keeps separate and reproducible.

Was this cheat sheet helpful?

Explore Topics

#PythonVirtualEnvironmentsPip#PythonVirtualEnvironmentsPipCheatSheet#Programming#Beginner#CreatingActivatingAVenv#InstallingManagingPackages#RequirementsTxtWorkflow#UsefulPipFlags#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech

Professional Web Designing Services

  • Responsive Websites
  • E-commerce Solutions
  • SEO Friendly Design
  • Fast & Secure
  • Support & Maintenance
Get a Free Quote

Share this Cheat Sheet