Skip to content

BUG: matplotlib backend issue when building documentation with sphinx #54259

Closed
@jadelsoufi

Description

@jadelsoufi

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

I get the following matplotlib backend error when building the html documentation with sphinx on my terminal


(pandas-dev) ~\pandas\doc>python make.py html
+ meson compile
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: C:\Users\jadel\miniforge3\envs\pandas-dev\Library\bin\ninja.EXE
[1/1] Generating write_version_file with a custom command
Running Sphinx v6.2.1
+ meson compile
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: C:\Users\jadel\miniforge3\envs\pandas-dev\Library\bin\ninja.EXE
[1/1] Generating write_version_file with a custom command
[autosummary] generating autosummary for: development\community.rst, development\contributing.rst, development\contributing_codebase.rst, development\contributing_docstring.rst, development\contributing_documentation.rst, development\contributing_environment.rst, development\contributing_gitpod.rst, development\copy_on_write.rst, development\debugging_extensions.rst, development\developer.rst, ..., whatsnew\v1.5.0.rst, whatsnew\v1.5.1.rst, whatsnew\v1.5.2.rst, whatsnew\v1.5.3.rst, whatsnew\v2.0.0.rst, whatsnew\v2.0.1.rst, whatsnew\v2.0.2.rst, whatsnew\v2.0.3.rst, whatsnew\v2.0.4.rst, whatsnew\v2.1.0.rst
loading intersphinx inventory from https://dateutil.readthedocs.io/en/latest/objects.inv...
loading intersphinx inventory from https://matplotlib.org/stable/objects.inv...
loading intersphinx inventory from https://numpy.org/doc/stable/objects.inv...
loading intersphinx inventory from https://pandas-gbq.readthedocs.io/en/latest/objects.inv...
loading intersphinx inventory from https://pylib.readthedocs.io/en/latest/objects.inv...
loading intersphinx inventory from https://docs.python.org/3/objects.inv...
loading intersphinx inventory from https://docs.scipy.org/doc/scipy/objects.inv...
loading intersphinx inventory from https://arrow.apache.org/docs/objects.inv...
building [mo]: targets for 0 po files that are out of date
writing output...
building [html]: targets for 2471 source files that are out of date
updating environment: [new config] 2471 added, 0 changed, 0 removed
WARNING: ources... [  1%] getting_started/intro_tutorials/04_plotting
>>>-------------------------------------------------------------------------
Warning in C:\Users\jadel\Documents\myfirstcontribution\pandas\doc\source\getting_started\intro_tutorials\04_plotting.rst at block ending on line 70
Specify :okwarning: as an option in the ipython:: block to suppress this message
----------------------------------------------------------------------------
<ipython-input-6-1eb00ff78cf2>:1: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
  plt.show()
<<<-------------------------------------------------------------------------

Exception occurred:
  File "C:\Users\jadel\miniforge3\envs\pandas-dev\lib\site-packages\IPython\sphinxext\ipython_directive.py", line 600, in process_input
    raise RuntimeError('Non Expected warning in `{}` line {}'.format(filename, lineno))
RuntimeError: Non Expected warning in `C:\Users\jadel\Documents\myfirstcontribution\pandas\doc\source\getting_started\intro_tutorials\04_plotting.rst` line 70
The full traceback has been saved in C:\Users\jadel\AppData\Local\Temp\sphinx-err-ed_ytjnj.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!


### Issue Description

Using pandas doc files, Sphinx is unable to build the documentation because matplotlib backend is set to 'agg' which is a non-GUI backend

### Expected Behavior

I expected Sphinx to be able to create the html documents

### Installed Versions

<details>

INSTALLED VERSIONS
------------------
commit           : 3c01ce2af5099a8a830195b2050d3a4036d14ff3
python           : 3.10.12.final.0
python-bits      : 64
OS               : Windows
OS-release       : 10
Version          : 10.0.22621
machine          : AMD64
processor        : Intel64 Family 6 Model 165 Stepping 2, GenuineIntel
byteorder        : little
LC_ALL           : None
LANG             : None
LOCALE           : fr_FR.cp1252

pandas           : 2.1.0.dev0+1273.g3c01ce2af5.dirty
numpy            : 1.24.4
pytz             : 2023.3
dateutil         : 2.8.2
setuptools       : 68.0.0
pip              : 23.2
Cython           : 0.29.33
pytest           : 7.4.0
hypothesis       : 6.81.2
sphinx           : 6.2.1
blosc            : None
feather          : None
xlsxwriter       : 3.1.2
lxml.etree       : 4.9.3
html5lib         : 1.1
pymysql          : 1.4.6
psycopg2         : 2.9.6
jinja2           : 3.1.2
IPython          : 8.14.0
pandas_datareader: None
bs4              : 4.12.2
bottleneck       : 1.3.7
brotli           :
fastparquet      : 2023.7.0
fsspec           : 2023.6.0
gcsfs            : 2023.6.0
matplotlib       : 3.7.2
numba            : 0.57.1
numexpr          : 2.8.4
odfpy            : None
openpyxl         : 3.1.2
pandas_gbq       : None
pyarrow          : 12.0.1
pyreadstat       : 1.2.2
pyxlsb           : 1.0.10
s3fs             : 2023.6.0
scipy            : 1.11.1
snappy           :
sqlalchemy       : 2.0.19
tables           : 3.8.0
tabulate         : 0.9.0
xarray           : 2023.7.0
xlrd             : 2.0.1
zstandard        : 0.19.0
tzdata           : 2023.3
qtpy             : None
pyqt5            : None

</details>

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions