{"record":{"id":"3a4d58f04fd0617f","repo":"pola-rs/polars","slug":"required-package-torch-not-installed-please-ins","errorCode":null,"errorMessage":"Required package 'torch' not installed.\nPlease install it using the command `pip install torch`.","messagePattern":"Required package 'torch' not installed\\.\nPlease install it using the command `pip install torch`\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/ml/torch.py","lineNumber":29,"sourceCode":"if TYPE_CHECKING:\n    import sys\n    from collections.abc import Sequence\n\n    from torch import Tensor, memory_format\n\n    if sys.version_info >= (3, 11):\n        from typing import Self\n    else:\n        from typing_extensions import Self\ntry:\n    import torch\n    from torch.utils.data import TensorDataset\nexcept ImportError:\n    msg = (\n        \"Required package 'torch' not installed.\\n\"\n        \"Please install it using the command `pip install torch`.\"\n    )\n    raise ImportError(msg) from None\n\n\n__all__ = [\"PolarsDataset\"]\n\n\nclass PolarsDataset(TensorDataset):  # type: ignore[misc]\n    \"\"\"\n    TensorDataset class specialized for use with Polars DataFrames.\n\n    .. warning::\n        This functionality is considered **unstable**. It may be changed\n        at any point without it being considered a breaking change.\n\n    Parameters\n    ----------\n    frame\n        Polars DataFrame containing the data that will be retrieved as Tensors.\n    label","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/pola-rs/polars/blob/9b5d73fd00236295624374b075d16b1fe6ec6df9/py-polars/src/polars/ml/torch.py#L11-L47","documentation":"Import-time failure in polars.ml.torch: the `torch` package (imported together with torch.utils.data.TensorDataset) is not installed, so the PolarsDataset helper built on TensorDataset cannot be defined and the module cannot load at all.","triggerScenarios":"Thrown at py-polars/src/polars/ml/torch.py:29 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Install torch: pip install torch."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"9b5d73fd00236295624374b075d16b1fe6ec6df9","analyzedAt":"2026-08-19T12:15:06.350Z","contentChangedAt":"2026-08-19T12:15:06.350Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}