Skip to main content

Virtual Environments

PPM automatically manages Python virtual environments to ensure clean, isolated dependency management alongside your JavaScript packages. This page explains how PPM’s virtual environment system works and how to customize it for your needs.

Why Virtual Environments Matter

The Problem

Python’s global package installation can lead to:
  • Dependency conflicts between different projects
  • Version incompatibilities when switching between projects
  • System pollution with packages not needed globally
  • Deployment inconsistencies between development and production

PPM’s Solution

PPM automatically creates and manages virtual environments: Automatic creation when initializing projects
Intelligent activation for all Python operations
Cross-platform compatibility (Windows, macOS, Linux)
Integration with JavaScript workflows
Zero configuration required for most use cases

How It Works

Automatic Environment Creation

When you run ppm init or ppm install, PPM:
1

Detection

Scans for existing virtual environments:
  • .venv/ directory
  • venv/ directory
  • env/ directory
  • Custom paths specified in configuration
2

Creation

Creates a new virtual environment if none exists:
3

Activation

Automatically activates the environment for Python operations:
4

Installation

Installs Python dependencies within the isolated environment

Environment Lifecycle

PPM manages the complete lifecycle:

Configuration Options

Basic Configuration

Configure virtual environments in project.toml:

Advanced Configuration

Multiple Environments

Define different environments for different use cases:
Switch between environments:

Environment Management Commands

Creation and Activation

Information and Status

Maintenance

Python Version Management

Version Detection

PPM automatically detects available Python versions:

Version Selection Priority

PPM uses this order to select Python versions:
  1. Project configuration (project.toml)
  2. Runtime argument (--python 3.10)
  3. Environment variable (PPM_PYTHON_VERSION)
  4. pyproject.toml (if present)
  5. .python-version file (pyenv compatibility)
  6. System default Python

Multiple Python Versions

Work with multiple Python versions:
Test across versions:

Integration Patterns

With JavaScript Tools

PPM seamlessly integrates Python virtual environments with JavaScript tooling:

With Docker

Use PPM virtual environments in Docker:

With CI/CD

GitHub Actions example:

Troubleshooting

Common Issues

Problem: Python packages not found or wrong version usedSolution:
Problem: Cannot create virtual environment due to permissionsSolution:
Problem: PPM cannot find specified Python versionSolution:
Problem: pip cannot download packages due to SSL errorsSolution:

Debugging Commands

Best Practices

Project Structure

Organize your virtual environments consistently:

Environment Naming

Use descriptive names for multiple environments:

Dependency Management

Keep virtual environments clean:

Team Collaboration

Ensure consistent environments across team:
  1. Commit project.toml and ppm.lock
  2. Include .venv/ in .gitignore
  3. Document any special setup requirements
  4. Use exact Python versions in production
  5. Test with multiple Python versions in CI

PPM’s virtual environment management eliminates the complexity of Python environment setup while maintaining full compatibility with existing Python tooling. The automatic creation and activation ensures your team never has to worry about environment issues again.