{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreigd72epviwdog7u3arddu4ksadaof67fu22fvvogfrmbycbdtaciy",
    "uri": "at://did:plc:pgryn3ephfd2xgft23qokfzt/app.bsky.feed.post/3mnt3iusn7e52"
  },
  "path": "/t/chapter-1-questions/6797?page=6#post_124",
  "publishedAt": "2026-06-09T00:54:02.000Z",
  "site": "https://discuss.huggingface.co",
  "tags": [
    "Transformers pipelines docs",
    "Transformers installation check",
    "AttributeError: module 'sympy' has no attribute 'printing'",
    "pipeline import fails with torchvision::nms mismatch",
    "Failed to import transformers.pipelines ... operator torchvision::nms does not exist",
    "Colab past runtime FAQ",
    "Course issue: Chapter 1 notebook drift",
    "Course issue: grouped_entities removed/deprecated"
  ],
  "textContent": "Hmm, it works on my Colab environment, so maybe it’s something like this?:\n\n* * *\n\nI don’t think the three-line Course snippet itself is the main problem here.\n\nThis code is still a normal way to do a first Transformers smoke test:\n\n\n    from transformers import pipeline\n\n    classifier = pipeline(\"sentiment-analysis\")\n    classifier(\"I’ve been waiting for a Hugging Face course my whole life.\")\n\n\nThe current Transformers docs still describe `pipeline` as the high-level inference API, and the installation docs still use a `pipeline(\"sentiment-analysis\")` command as an install check:\n\n  * Transformers pipelines docs\n  * Transformers installation check\n\n\n\nSo I would read your traceback as an **environment / dependency-stack issue** , not as “the Chapter 1 example is conceptually wrong”.\n\n## What looks suspicious in the traceback\n\nThe important part is not really the top-level `pipeline(\"sentiment-analysis\")` line. The traceback eventually goes through something like this:\n\n\n    transformers\n      -> transformers.pipelines\n      -> transformers.video_utils\n      -> torchvision.io\n      -> torch._dynamo\n      -> torch.fx.experimental.symbolic_shapes\n      -> torch.utils._sympy.functions\n      -> sympy.printing\n\n\nand then fails with:\n\n\n    AttributeError: module 'sympy' has no attribute 'printing'\n\n\nThat means the failure happens while importing the PyTorch / torchvision / SymPy-related stack. The sentiment-analysis model has not really had a chance to run yet.\n\nIn other words, this is probably closer to:\n\n> “Transformers tried to import pipeline helpers, that pulled in torchvision / PyTorch internals, and the installed PyTorch + SymPy combination was not in a clean compatible state.”\n\nrather than:\n\n> “The sentiment-analysis pipeline example is obsolete.”\n\n## I tried a clean Colab Free CPU runtime\n\nFor comparison, I tried the same basic snippet on my Colab environment without setting an `HF_TOKEN`.\n\nIt worked.\n\nMy environment was:\n\nPackage | Version\n---|---\nPython | `3.12.13`\n`transformers` | `5.9.0`\n`torch` | `2.11.0+cpu`\n`torchvision` | `0.26.0+cpu`\n`torchaudio` | `2.11.0+cpu`\n`sympy` | `1.14.0`\n`huggingface_hub` | `1.17.0`\n`tokenizers` | `0.22.2`\n`safetensors` | `0.7.0`\n\nThe output was:\n\n\n    [{'label': 'POSITIVE', 'score': 0.9984577894210815}]\n\n\nI also saw the usual Colab warning about not having an `HF_TOKEN`, but that was not fatal. Public models can still be downloaded without a token, although authenticated requests may have better rate limits.\n\nSo this does not look like a general “current Colab cannot run Chapter 1” problem.\n\n## Similar known pattern\n\nThere are a few similar-looking dependency-drift cases around this area:\n\nPattern | Why it is relevant\n---|---\nAttributeError: module 'sympy' has no attribute 'printing' | Similar failure shape: PyTorch symbolic-shape code reaches for `sympy.printing` and crashes.\npipeline import fails with torchvision::nms mismatch | Text-only pipeline usage can still fail because `torchvision` gets imported during the Transformers import path.\nFailed to import transformers.pipelines ... operator torchvision::nms does not exist | Another example where `from transformers import pipeline` surfaces a lower-level `torch` / `torchvision` mismatch.\nColab past runtime FAQ | Colab runtimes and preinstalled packages change over time, which is exactly the kind of thing that can break old course notebooks or old notebook sessions.\nCourse issue: Chapter 1 notebook drift | Not the same root cause, but it shows that Course notebooks can drift as Transformers and hosted runtimes evolve.\nCourse issue: grouped_entities removed/deprecated | Another Chapter 1 drift example, though this one is about a changed pipeline argument rather than your SymPy traceback.\n\nThe closest match to your exact traceback is the SymPy/PyTorch-looking `sympy.printing` problem. The closest structural match is the Transformers issues where a text pipeline fails because `torchvision` is imported underneath.\n\n## What I would try first\n\nFirst, restart the runtime and run only the minimal snippet again.\n\nIn Colab:\n\n\n    Runtime -> Restart runtime\n\n\nThen run:\n\n\n    from transformers import pipeline\n\n    classifier = pipeline(\"sentiment-analysis\")\n    classifier(\"I’ve been waiting for a Hugging Face course my whole life.\")\n\n\nIf that still fails, collect the versions:\n\n\n    import sys\n    import importlib.metadata as md\n\n    print(\"python:\", sys.version)\n\n    for pkg in [\"transformers\", \"torch\", \"torchvision\", \"torchaudio\", \"sympy\", \"huggingface_hub\", \"tokenizers\", \"safetensors\"]:\n        try:\n            print(f\"{pkg}: {md.version(pkg)}\")\n        except md.PackageNotFoundError:\n            print(f\"{pkg}: not installed\")\n\n\n## Small workaround to test the SymPy hypothesis\n\nBecause your error is specifically:\n\n\n    AttributeError: module 'sympy' has no attribute 'printing'\n\n\nit may be worth testing whether explicitly importing the SymPy printing submodule changes anything:\n\n\n    import sympy.printing\n\n    from transformers import pipeline\n\n    classifier = pipeline(\"sentiment-analysis\")\n    classifier(\"I’ve been waiting for a Hugging Face course my whole life.\")\n\n\nIf that works, I would treat it as an import-order / dependency-stack workaround, not as the final conceptual fix.\n\n## If the workaround does not help\n\nThen I would try repairing the package stack.\n\nStart small:\n\n\n    !pip install -U -q sympy\n\n\nThen restart the runtime:\n\n\n    Runtime -> Restart runtime\n\n\nand retry:\n\n\n    from transformers import pipeline\n\n    classifier = pipeline(\"sentiment-analysis\")\n    classifier(\"I’ve been waiting for a Hugging Face course my whole life.\")\n\n\nIf that still fails, try reinstalling the relevant stack together:\n\n\n    !pip install -U -q transformers torch torchvision torchaudio sympy\n\n\nThen restart the runtime again.\n\n## Optional: make the model explicit\n\nThe default pipeline currently chooses a small public sentiment model automatically, but for debugging it is often nicer to be explicit:\n\n\n    from transformers import pipeline\n\n    classifier = pipeline(\n        \"sentiment-analysis\",\n        model=\"distilbert/distilbert-base-uncased-finetuned-sst-2-english\",\n    )\n\n    classifier(\"I’ve been waiting for a Hugging Face course my whole life.\")\n\n\nThis avoids confusing “default model selection” with the real import problem.\n\n## My current guess\n\nMy guess is:\n\n  1. the Course snippet is probably fine;\n  2. your Colab session had a stale or inconsistent dependency state;\n  3. the actual breakage is in the `torch` / `torchvision` / `sympy` import chain;\n  4. a clean runtime, a SymPy update, or reinstalling the PyTorch-family packages together should probably fix it.\n\n\n\nSo I would not start by rewriting the Course example. I would first verify the environment versions and try a clean runtime.",
  "title": "Chapter 1 questions"
}