Skip to content

import preliz fails on matplotlib 3.11 (module 'matplotlib.style' has no attribute 'core') #726

Description

@anevolbap

Describe the bug

import preliz fails with matplotlib 3.11.0. The line style.core.USER_LIBRARY_PATHS.append(...) in preliz/__init__.py runs at import time and raises AttributeError. matplotlib 3.11 no longer auto-imports the matplotlib.style.core submodule, so the style.core attribute access fails (the submodule still exists, but import matplotlib.style.core is now required to reach it). This affects 0.24.0, 0.25.0, 0.26.0 (latest), and main.

To Reproduce

pip install "matplotlib==3.11.0" "preliz==0.26.0"
python -c "import preliz"

Stack trace:

File ".../preliz/__init__.py", line 31, in <module>
    style.core.USER_LIBRARY_PATHS.append(_preliz_style_path)
AttributeError: module 'matplotlib.style' has no attribute 'core'

Expected behavior

import preliz works on matplotlib 3.11. A fix mirroring the one arviz-plots used (use the new top-level location, fall back to .core for old matplotlib):

if hasattr(style, "USER_LIBRARY_PATHS"):
    style.USER_LIBRARY_PATHS.append(_preliz_style_path)
else:
    style.core.USER_LIBRARY_PATHS.append(_preliz_style_path)
style.reload_library()

Additional context

matplotlib 3.11.0, preliz 0.26.0, Python 3.12, Linux. Found while trying to drop a matplotlib<3.11 pin in pymc-marketing, where preliz is imported lazily via pymc_extras.prior.Prior.constrain.

I reproduced it with uv in a throwaway environment:

uv run --python 3.12 --with "matplotlib==3.11.0" --with "preliz==0.26.0" python -c "import preliz"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions