{"record":{"id":"bef4c742ddac732e","repo":"huggingface/transformers","slug":"you-need-to-install-libcst-to-run-this-command","errorCode":null,"errorMessage":"You need to install `libcst` to run this command -> `pip install libcst`","messagePattern":"You need to install `libcst` to run this command -> `pip install libcst`","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/cli/add_new_model_like.py","lineNumber":555,"sourceCode":"    \"\"\"\n    Creates a new model module like a given model of the Transformers library.\n\n    Args:\n        repo_path (`Path`):\n            The path to the root of the Transformers repository.\n        old_model_infos (`ModelInfos`):\n            The structure containing the class information of the old model.\n        new_lowercase_name (`str`):\n            The new lowercase model name.\n        new_model_paper_name (`str`):\n            The fully cased name (as in the official paper name) of the new model.\n        filenames_to_add (`list[tuple[str, bool]]`):\n            A list of tuples of all potential filenames to add for a new model, along a boolean flag describing if we\n            should add this file or not. For example, [(`modeling_xxx.px`, True), (`configuration_xxx.py`, True), (`tokenization_xxx.py`, False),...]\n    \"\"\"\n    # As the import was protected, raise if not present (as it's actually a hard dependency for this command)\n    if not is_libcst_available():\n        raise ValueError(\"You need to install `libcst` to run this command -> `pip install libcst`\")\n\n    old_lowercase_name = old_model_infos.lowercase_name\n\n    # 1. We create the folder for our new model\n    new_module_folder = repo_path / \"src\" / \"transformers\" / \"models\" / new_lowercase_name\n    os.makedirs(new_module_folder, exist_ok=True)\n\n    # 2. Create and add the modular file\n    modular_file, public_classes = create_modular_file(\n        repo_path, old_model_infos, new_lowercase_name, filenames_to_add\n    )\n    with open(new_module_folder / f\"modular_{new_lowercase_name}.py\", \"w\") as f:\n        f.write(modular_file)\n\n    # 3. Create and add the __init__.py\n    init_file = create_init_file(old_lowercase_name, new_lowercase_name, filenames_to_add)\n    with open(new_module_folder / \"__init__.py\", \"w\") as f:\n        f.write(init_file)","sourceCodeStart":537,"sourceCodeEnd":573,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/cli/add_new_model_like.py#L537-L573","documentation":"The add-new-model-like command uses libcst to parse and rewrite the source files of the base model into a new modular file. The import of libcst is optional at module level, so the command explicitly checks is_libcst_available() and raises ValueError (not ImportError) telling you to pip install libcst when it is absent.","triggerScenarios":"Running `transformers add-new-model-like ...` in an environment where libcst is not installed; a minimal/pinned install of transformers that skips optional dev dependencies; CI containers that only install runtime requirements.","commonSituations":"Fresh contributor environments; tox/nox environments that install only `pip install -e .` without dev extras; caching/lock files that omit libcst.","solutions":["pip install libcst","Or install transformers dev extras: pip install -e \"transformers[dev]\" from the repo","Re-run the add-new-model-like command afterwards"],"exampleFix":"# before\ntransformers add-new-model-like ...  # ValueError: install libcst\n\n# after\npip install libcst\ntransformers add-new-model-like ...","handlingStrategy":"validation","validationCode":"try:\n    import libcst  # noqa\n    ok = True\nexcept ImportError:\n    ok = False\nif not ok:\n    raise SystemExit(\"pip install libcst before running add-new-model-like\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Install dev tooling before contributing: pip install -e \".[dev]\"","Add libcst to your contributor environment setup script","Check is_libcst_available() in wrapper scripts that automate this command"],"tags":["cli","missing-dependency","libcst","valueerror","developer-tooling"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}