direnv

direnv is an environment management tool that automatically “loads and unloads environment variables depending on the current directory” in your shell. While not Python-specific, direnv is particularly useful for Python development by helping manage project-specific environments and settings.

ℹ️
direnv works with any programming language or shell, but has special integrations with Python tools and virtual environments.

Core Functionality

  • Automatically activates/deactivates environment variables when entering/leaving directories in your shell
  • Loads environment variables from .envrc files

Python Integration

direnv has built-in support for Python virtual environments through:

  • Automatic virtual environment activation
  • Support for environment variables used by Python tools
  • Handling of Python-specific path configurations

For example, .envrc for a Python project might look like:

# Activate virtual environment
layout python python3.11

# Set project-specific variables
export FLASK_ENV=development

Pros

  • Seamless environment switching between projects
  • Language-agnostic but Python-friendly

Cons

  • Requires shell integration setup
  • Learning curve for .envrc syntax
  • Can conflict with other environment managers
⚠️
While direnv has robust support for traditional Python virtual environments, it does not yet natively support uv-created virtual environments. The community is actively working on this integration. For now, users leveraging uv must manually configure environment activation or use uv run directly for project execution.

Learn More

Last updated on

Please submit corrections and feedback...