Skip to content

Importerror with matplotlib > 3.7 "cannot import name 'common_texification' from 'matplotlib.backends.backend_pgf'" #595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JohannesAck opened this issue Nov 27, 2023 · 2 comments

Comments

@JohannesAck
Copy link

Please provide a minimal working example (MWE) that shows what isn't working as
expected. Needed is

  • the Python code,
import tikzplotlib
  • the output
  File "/workspaces/jax_rl_tests/tikzplotlibdebug.py", line 12, in <module>
    import tikzplotlib
  File "/usr/local/lib/python3.10/dist-packages/tikzplotlib/__init__.py", line 5, in <module>
    from ._save import Flavors, get_tikz_code, save
  File "/usr/local/lib/python3.10/dist-packages/tikzplotlib/_save.py", line 11, in <module>
    from . import _axes
  File "/usr/local/lib/python3.10/dist-packages/tikzplotlib/_axes.py", line 3, in <module>
    from matplotlib.backends.backend_pgf import (
ImportError: cannot import name 'common_texification' from 'matplotlib.backends.backend_pgf' (/usr/local/lib/python3.10/dist-packages/matplotlib/backends/backend_pgf.py)

It seems tikzplotlib is using a deprecated API, which was made internal from matplotlib>3.7.

An easy workaround right now is to downgrade to matplotlib before 3.5.

To fix, it would probably possible to use the (internal) _escape_tex API.
https://github.com/matplotlib/matplotlib/blob/336028f4d521a23d9ea2de88b1faf82eddfa5b52/lib/matplotlib/backends/backend_pgf.py#L101

@FriedrichFroebel
Copy link

This seems to be a duplicate of #559.

@JohannesAck
Copy link
Author

You're right, It is a duplicate.
Still I think it's helpful to have this one as well, as searching the error I got didn't lead to that issue.

As a workaround that worked for me, I downgraded matplotlib to 3.6 and used this forked version of tikzplotlib:
https://github.com/Vadim-Gorshanov/tikzplotlib/tree/7ba04ed08155637be53d58f762b74f87e6f85890

@nschloe nschloe closed this as not planned Won't fix, can't repro, duplicate, stale Nov 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants