pytorch - 💡(How to fix) Fix Cannot build documentation (`RecursionError`) [2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
pytorch/pytorch#178988Fetched 2026-04-08 02:24:43
View on GitHub
Comments
2
Participants
2
Timeline
26
Reactions
0
Timeline (top)
mentioned ×10subscribed ×10labeled ×4commented ×2

Error Message

(docs) yalihupokn@zoqu-endiman:/Repositories/dc/PT/pytorch/docs$ make latexpdf Traceback (most recent call last): File "/home/yalihupokn/Repositories/dc/PT/pytorch/docs/source/scripts/build_activation_images.py", line 12, in <module> import torch ModuleNotFoundError: No module named 'torch' make: *** [Makefile:17: figures] Error 1 (docs) yalihupokn@zoqu-endiman:/Repositories/dc/PT/pytorch/docs$

Code Example

git clone --filter=blob:none --no-checkout https://github.com/pytorch/pytorch/
git sparse-checkout init — cone
git sparse-checkout set docs aten test
git checkout main

cd docs

uv venv
source .venv/bin/activate
uv pip install -r requirements.txt
make latexpdf

---

(docs) yalihupokn@zoqu-endiman:~/Repositories/dc/PT/pytorch/docs$ make latexpdf
Traceback (most recent call last):
  File "/home/yalihupokn/Repositories/dc/PT/pytorch/docs/source/scripts/build_activation_images.py", line 12, in <module>
    import torch
ModuleNotFoundError: No module named 'torch'
make: *** [Makefile:17: figures] Error 1
(docs) yalihupokn@zoqu-endiman:~/Repositories/dc/PT/pytorch/docs$

---

File "/usr/lib64/python3.14/copy.py", line 138, in deepcopy
    y = copier(memo)
  File "/home/yalihupokn/Repositories/dc/PT/pytorch/docs/.venv/lib64/python3.14/site-packages/matplotlib/path.py", line 287, in __deepcopy__
    p = copy.deepcopy(super(), memo)
  File "/usr/lib64/python3.14/copy.py", line 157, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/usr/lib64/python3.14/copy.py", line 234, in _reconstruct
    y = func(*args)
  File "/usr/lib64/python3.14/copy.py", line 233, in <genexpr>
    args = (deepcopy(arg, memo) for arg in args)
            ~~~~~~~~^^^^^^^^^^^
RecursionError: maximum recursion depth exceeded
make: *** [Makefile:17: figures] Error 1
(docs) yalihupokn@zoqu-endiman:~/Repositories/dc/PT/pytorch/docs$
RAW_BUFFERClick to expand / collapse

📚 The doc issue

Anyone know what's going on? I'm pretty sure I've covered everything

git clone --filter=blob:none --no-checkout https://github.com/pytorch/pytorch/
git sparse-checkout init — cone
git sparse-checkout set docs aten test
git checkout main

cd docs

uv venv
source .venv/bin/activate
uv pip install -r requirements.txt
make latexpdf

I then get ModuleNotFoundError: No module named 'torch', and after uv pip install torch

<details> <summary> Logs </summary
(docs) yalihupokn@zoqu-endiman:~/Repositories/dc/PT/pytorch/docs$ make latexpdf
Traceback (most recent call last):
  File "/home/yalihupokn/Repositories/dc/PT/pytorch/docs/source/scripts/build_activation_images.py", line 12, in <module>
    import torch
ModuleNotFoundError: No module named 'torch'
make: *** [Makefile:17: figures] Error 1
(docs) yalihupokn@zoqu-endiman:~/Repositories/dc/PT/pytorch/docs$

It outputs this line so many times I cannot scroll back to the ModuleNotFoundErorr in the terminal anymore:

  File "/usr/lib64/python3.14/copy.py", line 138, in deepcopy
    y = copier(memo)
  File "/home/yalihupokn/Repositories/dc/PT/pytorch/docs/.venv/lib64/python3.14/site-packages/matplotlib/path.py", line 287, in __deepcopy__
    p = copy.deepcopy(super(), memo)
  File "/usr/lib64/python3.14/copy.py", line 157, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/usr/lib64/python3.14/copy.py", line 234, in _reconstruct
    y = func(*args)
  File "/usr/lib64/python3.14/copy.py", line 233, in <genexpr>
    args = (deepcopy(arg, memo) for arg in args)
            ~~~~~~~~^^^^^^^^^^^
RecursionError: maximum recursion depth exceeded
make: *** [Makefile:17: figures] Error 1
(docs) yalihupokn@zoqu-endiman:~/Repositories/dc/PT/pytorch/docs$
</details>

Suggest a potential alternative/fix

Unfortunately using python -m venv .venv did not help either :/

cc @malfet @seemethere @svekars @sekyondaMeta @AlannaBurke

extent analysis

TL;DR

The issue can be resolved by ensuring that the torch module is properly installed and imported in the virtual environment.

Guidance

  • Verify that the torch module is installed in the virtual environment by running pip install torch instead of uv pip install torch, as uv is not a standard command.
  • Check the Python version used to create the virtual environment and ensure it is compatible with the torch module.
  • Try creating the virtual environment using the standard command python -m venv .venv instead of uv venv.
  • Ensure that the virtual environment is activated before running make latexpdf.

Example

No code snippet is provided as the issue is more related to the environment setup and package installation.

Notes

The issue seems to be related to the virtual environment setup and package installation. The use of uv instead of python to create and manage the virtual environment might be causing the issue.

Recommendation

Apply workaround: Use the standard command python -m venv .venv to create the virtual environment and pip install torch to install the torch module, as this is a more reliable and widely-supported approach.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING