Description
Bug summary
Matplotlib generates as a side-effect a font cache during import time. This is needed for plotting functionality to work. Unfortunately, this also means that any (transitive) dependency that eagerly imports matplotlib will now result in the cache to be generated, even when the user is at no time using matplotlib.
I opened an issue about this 8 years ago #7592. At the time the issue was regarding Linux. Now, it seems the behaviour has changed on MacOS and it happens there as well.
Code for reproduction
import matplotlib
Actual outcome
/nix/store/774r81hjzn2p64jnsdyk0cl2rbjabghj-python3-3.12.3-env/lib/python3.12/site-packages/matplotlib/font_manager.py:270: in _get_macos_fonts
subprocess.check_output(["system_profiler", "-xml", "SPFontsDataType"]))
/nix/store/65ackbgqn02p6fy75rksjbp17zj6440j-python3-3.12.3/lib/python3.12/subprocess.py:466: in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
/nix/store/65ackbgqn02p6fy75rksjbp17zj6440j-python3-3.12.3/lib/python3.12/subprocess.py:548: in run
with Popen(*popenargs, **kwargs) as process:
/nix/store/65ackbgqn02p6fy75rksjbp17zj6440j-python3-3.12.3/lib/python3.12/subprocess.py:1026: in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
/nix/store/65ackbgqn02p6fy75rksjbp17zj6440j-python3-3.12.3/lib/python3.12/subprocess.py:1955: in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
E FileNotFoundError: [Errno 2] No such file or directory: 'system_profiler'
Expected outcome
Preferably no side-effect during import-time. Or, as a work-around, some option such as an environment variable to disable the side-effect.
Additional information
Obviously if packages would not import matplotlib eagerly this would not be an issue. However, as a end-user this cannot be controlled. Anywhere in the dependency-tree one could import a library that is not required per se. But that does not mean libraries should just do side-effects during import time. Having an environment variable to disable the cache building would already be great, as it would provide a way out, other than trying to patch a (transitive) dependency.
Operating system
OSX
Matplotlib Version
3.9.0
Matplotlib Backend
No response
Python version
3.12
Jupyter version
No response
Installation
None