运行sphinx-build命令时出现AttributeError: 'Values' object has no attribute 'tab_width'错误,求解决方案
This error is caused by a compatibility conflict between your outdated Sphinx version (3.0.3) and the version of recommonmark you have installed. Newer releases of recommonmark changed how they handle document parsing, which breaks an assumption in Sphinx's autodoc extension (hence the tab_width AttributeError). Here are three actionable ways to fix this:
1. Downgrade recommonmark to a compatible version
The quickest fix is to roll back recommonmark to a version that plays nice with Sphinx 3.0.3. Version 0.6.0 is confirmed to work:
pip install recommonmark==0.6.0
Once installed, re-run your build command to check if the error is resolved.
2. Upgrade Sphinx to a Python 3.6-compatible newer version
Sphinx 3.0.3 is quite outdated—upgrading to a later version that still supports Python 3.6 will resolve this compatibility issue. The latest Sphinx version that works with Python 3.6 is 4.5.0:
pip install sphinx==4.5.0
This update also fixes several other bugs and improves extension compatibility overall.
3. Switch to myst-parser (recommended long-term fix)
recommonmark is no longer actively maintained, and myst-parser is the official, supported replacement for Markdown in Sphinx. This is the best option to avoid similar issues down the line:
- First, remove recommonmark:
pip uninstall -y recommonmark - Install myst-parser:
pip install myst-parser - Update your Sphinx
conf.pyfile to replacerecommonmarkwithmyst_parserin the extensions list:extensions = [ # Keep your existing extensions like 'sphinx.ext.autodoc' 'myst_parser', ]
Myst-parser offers better Markdown support and regular updates, so this will future-proof your documentation setup.
After applying any of these fixes, re-run your build command:
sphinx-build -M html . _build
内容的提问来源于stack exchange,提问作者vvvvv

