Skip to content

[Bug]: AttributeError while trying to import matplotlib.pyplot #27289

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
dhondta opened this issue Nov 8, 2023 · 2 comments
Closed

[Bug]: AttributeError while trying to import matplotlib.pyplot #27289

dhondta opened this issue Nov 8, 2023 · 2 comments

Comments

@dhondta
Copy link

dhondta commented Nov 8, 2023

Bug summary

AttributeError while trying to import matplotlib.pyplot.

Code for reproduction

import matplotlib.pyplot

Actual outcome

$ python3
Python 3.11.6 (main, Oct  8 2023, 05:06:43) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/.local/lib/python3.11/site-packages/matplotlib/pyplot.py", line 66, in <module>
    from matplotlib.figure import Figure, FigureBase, figaspect
  File "/home/user/.local/lib/python3.11/site-packages/matplotlib/figure.py", line 43, in <module>
    from matplotlib import _blocking_input, backend_bases, _docstring, projections
  File "/home/user/.local/lib/python3.11/site-packages/matplotlib/projections/__init__.py", line 60, in <module>
    from mpl_toolkits.mplot3d import Axes3D
  File "/usr/lib/python3/dist-packages/mpl_toolkits/mplot3d/__init__.py", line 1, in <module>
    from .axes3d import Axes3D
  File "/usr/lib/python3/dist-packages/mpl_toolkits/mplot3d/axes3d.py", line 45, in <module>
    class Axes3D(Axes):
  File "/usr/lib/python3/dist-packages/mpl_toolkits/mplot3d/axes3d.py", line 723, in Axes3D
    set_zticklabels = _axis_method_wrapper(
                      ^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/lib/python3.11/site-packages/matplotlib/axes/_base.py", line 56, in __init__
    doc = inspect.getdoc(getattr(maxis.Axis, method_name))
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: type object 'Axis' has no attribute '_set_ticklabels'. Did you mean: 'set_ticklabels'?

Expected outcome

$ python3
Python 3.11.6 (main, Oct  8 2023, 05:06:43) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot
>>> 

Additional information

No response

Operating system

Ubuntu 22.04

Matplotlib Version

3.8.1

Matplotlib Backend

No response

Python version

3.11.6

Jupyter version

No response

Installation

pip

@dhondta dhondta changed the title [Bug]: [Bug]: AttributeError while trying to import matplotlib.pyplot Nov 8, 2023
@dhondta dhondta changed the title [Bug]: AttributeError while trying to import matplotlib.pyplot [Bug]: AttributeError while trying to import matplotlib.pyplot Nov 8, 2023
@ksunden
Copy link
Member

ksunden commented Nov 8, 2023

This is an alternate presentation of #26827, just with mpl 3.6 installed rather than mpl 3.5 (and thus a different exception, which the initial band-aid fix doesn't catch).

The short version is that you have a state where two incompatible versions of mpl are installed and it is selecting the wrong one for 3D support. See the other thread for more details

I'm going to close this as a duplicate so that we keep the conversation in one place, but feel free to add some context over there.

@ksunden ksunden closed this as not planned Won't fix, can't repro, duplicate, stale Nov 8, 2023
@QuLogic
Copy link
Member

QuLogic commented Nov 8, 2023

This is also exacerbated by the fact that Debian's non-default Python is completely busted. They have patched distro search paths to /usr/lib/python3/dist-packages, which has no minor version in it. Your Python 3.11 is not the default Python for Ubuntu 22.04 (that is 3.10), but because of these faulty search paths, it still sees the distribution files.

ksunden added a commit to ksunden/matplotlib that referenced this issue Nov 8, 2023
Needed for the same reasons as matplotlib#27178 (Namely that we should not be failing on import just because mpl_toolkits is broken), but mpl 3.6 presents with an AttributeError rather than ImportError

See discussion in matplotlib#26827 and matplotlib#27289

Just expanded liberally in case there are other presentations we have not seen
ksunden added a commit to ksunden/matplotlib that referenced this issue Nov 8, 2023
Needed for the same reasons as matplotlib#27178 (Namely that we should not be failing on import just because mpl_toolkits is broken), but mpl 3.6 presents with an AttributeError rather than ImportError

See discussion in matplotlib#26827 and matplotlib#27289

Just expanded liberally in case there are other presentations we have not seen
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