@@ -518,15 +518,21 @@ def _get_config_or_cache_dir(xdg_base_getter):
518
518
return str (configdir )
519
519
# If the config or cache directory cannot be created or is not a writable
520
520
# directory, create a temporary one.
521
- tmpdir = os .environ ["MPLCONFIGDIR" ] = \
522
- tempfile .mkdtemp (prefix = "matplotlib-" )
521
+ try :
522
+ tmpdir = tempfile .mkdtemp (prefix = "matplotlib-" )
523
+ except OSError as exc :
524
+ raise OSError (
525
+ f"Matplotlib requires access to a writable cache directory, but the "
526
+ f"default path ({ configdir } ) is not a writable directory, and a temporary "
527
+ f"directory could not be created; set the MPLCONFIGDIR environment "
528
+ f"variable to a writable directory" ) from exc
529
+ os .environ ["MPLCONFIGDIR" ] = tmpdir
523
530
atexit .register (shutil .rmtree , tmpdir )
524
531
_log .warning (
525
- "Matplotlib created a temporary config/cache directory at %s because "
526
- "the default path (%s) is not a writable directory; it is highly "
527
- "recommended to set the MPLCONFIGDIR environment variable to a "
528
- "writable directory, in particular to speed up the import of "
529
- "Matplotlib and to better support multiprocessing." ,
532
+ "Matplotlib created a temporary cache directory at %s because the default path "
533
+ "(%s) is not a writable directory; it is highly recommended to set the "
534
+ "MPLCONFIGDIR environment variable to a writable directory, in particular to "
535
+ "speed up the import of Matplotlib and to better support multiprocessing." ,
530
536
tmpdir , configdir )
531
537
return tmpdir
532
538
0 commit comments