{"record":{"id":"e01eb315aacf8269","repo":"huggingface/transformers","slug":"to-use-type-self-name-please-install-the-f","errorCode":null,"errorMessage":"To use {type(self).__name__}, please install the following dependencies: {specs}","messagePattern":"To use (.+?), please install the following dependencies: (.+?)","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"src/transformers/exporters/base.py","lineNumber":82,"sourceCode":"        # target the public API, not the build.\n        missing, drift = [], []\n        for pkg in self.required_packages:\n            exists, installed = _is_package_available(pkg, return_version=True)\n            if not exists:\n                missing.append(pkg)\n                continue\n            tested = self.tested_versions.get(pkg)\n            if tested is not None and installed != \"N/A\":\n                installed_base = installed.split(\"+\", 1)[0]\n                tested_base = tested.split(\"+\", 1)[0]\n                if installed_base != tested_base:\n                    drift.append((pkg, installed_base, tested_base))\n\n        if missing:\n            specs = \", \".join(\n                f\"{pkg}=={self.tested_versions[pkg]}\" if pkg in self.tested_versions else pkg for pkg in missing\n            )\n            raise ImportError(f\"To use {type(self).__name__}, please install the following dependencies: {specs}\")\n\n        # Enforce hard minimums; collect all violations and report once, rather than failing on the first.\n        outdated = []\n        for pkg, minimum in self.min_versions.items():\n            _, installed = _is_package_available(pkg, return_version=True)\n            if installed == \"N/A\" or version.parse(installed.split(\"+\", 1)[0]) < version.parse(minimum):\n                outdated.append(f\"{pkg}>={minimum} (found {installed})\")\n        if outdated:\n            raise ImportError(f\"{type(self).__name__} requires newer versions of: {', '.join(outdated)}\")\n\n        if drift:\n            details = \", \".join(f\"{pkg}: installed {got}, tested {want}\" for pkg, got, want in drift)\n            logger.warning(\n                f\"{type(self).__name__} is experimental and patches many backend internals; \"\n                f\"behaviour may differ from what was validated. Version drift detected — {details}. \"\n                f\"If you hit issues, try the tested versions.\"\n            )\n","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/exporters/base.py#L64-L100","documentation":"HfExporter's dependency guard raises ImportError when any package listed in the exporter's required_packages is not installed. The message names the exporter class (e.g. OnnxExporter, ExecutorchExporter) and the exact pip spec, pinning the tested version when one is recorded in tested_versions (e.g. onnx==1.21.0).","triggerScenarios":"Calling OnnxExporter.export without onnx/onnxscript installed, or ExecutorchExporter.export without executorch — the check runs as part of the exporter's dependency validation before any tracing work.","commonSituations":"Fresh environment or slim transformers install missing optional export extras; CI image built for training only; installing transformers[onnx]-style extras was skipped.","solutions":["Install exactly what the message specifies: pip install \"onnx==1.21.0\" \"onnxscript==0.7.0\" (or pip install executorch==1.3.1 for ExecuTorch).","Or install without pins if you accept drift: pip install onnx onnxscript.","Pre-check availability in your code with transformers.utils.is_package_available / importlib.util.find_spec before constructing the exporter."],"exampleFix":"# before\nOnnxExporter().export(model, inputs, OnnxConfig())  # ImportError: onnx, onnxscript\n\n# after (shell)\n# pip install onnx==1.21.0 onnxscript==0.7.0\nOnnxExporter().export(model, inputs, OnnxConfig())","handlingStrategy":"validation","validationCode":"from importlib.util import find_spec\n\nREQUIRED = {\"onnx\": \"onnx==1.21.0\", \"onnxscript\": \"onnxscript==0.7.0\"}  # read from exporter.required_packages\ndeps = {pkg: spec for pkg, spec in REQUIRED.items() if find_spec(pkg) is None}\nif deps:\n    raise SystemExit(\"pip install \" + \" \".join(deps.values()))","typeGuard":null,"tryCatchPattern":"try:\n    exporter.export(model, inputs, cfg)\nexcept ImportError as e:\n    if \"please install\" in str(e):\n        subprocess.check_call([sys.executable, \"-m\", \"pip\", \"install\", *parse_specs(e)])  # or surface to user\n    else:\n        raise","preventionTips":["Declare export extras in your project's requirements (onnx, onnxscript, executorch) up front","In containers, install optional deps in the image rather than at runtime","Check exporter.required_packages / .tested_versions programmatically before exporting"],"tags":["export","dependencies","import-error","environment"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}