Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Environment:Kornia Kornia PyTorch Python Environment

From Leeroopedia


Knowledge Sources
Domains Infrastructure, Computer_Vision
Last Updated 2026-02-09 15:00 GMT

Overview

Python 3.11+ environment with PyTorch >= 2.0.0 and kornia_rs >= 0.1.9 native backend for differentiable computer vision.

Description

This is the core runtime environment required to use the Kornia library. Kornia is built entirely on top of PyTorch and requires a modern Python runtime (3.11 or newer). The library uses a Rust-based native extension (kornia_rs) for high-performance image I/O operations using libjpeg-turbo and other native codecs. The packaging library is also required for version comparison utilities used internally by Kornia's compatibility layer.

Usage

Use this environment for any Kornia operation. This is the base prerequisite for all Kornia workflows including image augmentation, feature matching, edge detection, and ONNX pipelines. Every Implementation page in the Kornia wiki requires this environment.

System Requirements

Category Requirement Notes
OS Linux, macOS, Windows Cross-platform; `kornia_rs` provides native binaries per OS
Hardware CPU (minimum) GPU optional; see CUDA_GPU_Environment for GPU acceleration
Disk ~500MB For PyTorch + Kornia + kornia_rs installation

Dependencies

System Packages

  • No special system packages required for CPU-only usage
  • For `kornia_rs` image I/O: libjpeg-turbo is bundled in the wheel

Python Packages

  • `python` >= 3.11 (supports 3.11, 3.12, 3.13)
  • `torch` >= 2.0.0
  • `kornia_rs` >= 0.1.9
  • `packaging` (any version)

Credentials

No credentials are required for core Kornia functionality.

Quick Install

# Install Kornia (automatically pulls torch, kornia_rs, packaging)
pip install kornia

# Or install with specific PyTorch version
pip install torch>=2.0.0 kornia

Code Evidence

Python version requirement from `pyproject.toml:9`:

requires-python = ">=3.11"

Core dependencies from `pyproject.toml:32`:

dependencies = ["kornia_rs>=0.1.9", "packaging", "torch>=2.0.0"]

PyTorch version comparison utilities from `kornia/core/_compat.py:74-102`:

def torch_version_ge(major: int, minor: int, patch: Optional[int] = None) -> bool:
    """Check if the current PyTorch version is greater than or equal to the specified version."""
    _version = version.parse(torch_version())
    if patch is None:
        return _version >= version.parse(f"{major}.{minor}")
    else:
        return _version >= version.parse(f"{major}.{minor}.{patch}")

kornia_rs is imported directly (not lazy-loaded) for image I/O from `kornia/io/io.py:24`:

import kornia_rs

Common Errors

Error Message Cause Solution
`ModuleNotFoundError: No module named 'kornia_rs'` kornia_rs native extension not installed `pip install kornia_rs>=0.1.9`
`RuntimeError: Dynamo is not supported on Python 3.12+` torch.compile limitation on newer Python Downgrade to Python 3.11 or disable torch.compile
`ImportError: torch` PyTorch not installed `pip install torch>=2.0.0`

Compatibility Notes

  • Python 3.11+: Required minimum. Python 3.10 and earlier are not supported.
  • PyTorch JIT Scripting: Kornia uses `Optional[]`, `Union[]`, `List[]` typing syntax (not `X | None`) for compatibility with `torch.jit.script`. This is documented in `pyproject.toml` ruff ignore rules `UP006`, `UP007`, `UP035`.
  • torch.compile: Supported but may have issues on Python 3.12+. Kornia avoids in-place operations in critical paths to maintain `torch.compile()` compatibility.
  • MPS (Apple Silicon): Supported with fallbacks. Some operations like `torch.std_mean` have MPS-specific workarounds via `is_mps_tensor_safe()`.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment