Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Confusing error message when home config directory not writable #18011

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
trampgeek opened this issue Jul 22, 2020 · 4 comments Β· Fixed by #18014
Closed

Confusing error message when home config directory not writable #18011

trampgeek opened this issue Jul 22, 2020 · 4 comments Β· Fixed by #18014
Milestone

Comments

@trampgeek
Copy link

Bug report

Bug summary

If matplotlib is run in an environment without a writable home directory, a very confusing error message is printed in which the configdir and the tempdir are interchanged.

Code for reproduction

  1. In Linux, create a user someone with no home directory.

  2. Run Python with a command like

    sudo -u someone python3

  3. In the Python shell, type import matplotlib

Actual outcome

Matplotlib created a temporary config/cache directory at /root/.config/matplotlib because the default path (/tmp/matplotlib-9yoi7m8l) is not a writable directory; it is highly recommended to set the MPLCONFIGDIR environment variable to a writable directory, in particular to speed up the import of Matplotlib and to better support multiprocessing.

Expected outcome

Matplotlib created a temporary config/cache directory at /tmp/matplotlib-9yoi7m8l because the default path (/root/.config/matplotlib) is not a writable directory; it is highly recommended to set the MPLCONFIGDIR environment variable to a writable directory, in particular to speed up the import of Matplotlib and to better support multiprocessing.

Matplotlib version

  • Operating system: Ubuntu 18.04
  • Matplotlib version: 3.3.0
  • Matplotlib backend (print(matplotlib.get_backend())): agg
  • Python version: 3.9.0b4
  • Jupyter version (if applicable): N/A
  • Other libraries: N/A

Matplotlib was compiled from source. The error is at line 482 in __init__.py at the root level in the source tree. The parameters are the wrong way round.

QuLogic added a commit to QuLogic/matplotlib that referenced this issue Jul 22, 2020
@QuLogic QuLogic added this to the v3.3.1 milestone Jul 22, 2020
@YuantianGao
Copy link

I have the same issue, did you solve it?

@tacaswell
Copy link
Member

@YuantianGao Yes, we fixed the order of the paths in #18014 and this should be fixed in all versions after 3.3.1.

@ttarabula
Copy link

ttarabula commented Sep 23, 2021

Does anyone know if this warning message can be suppressed? If not, any chance there's interest in adding an environment variable to optionally suppress the warning?

something like (but better named ;):

index 71afd3928d..01f8d15fab 100644
--- a/lib/matplotlib/__init__.py
+++ b/lib/matplotlib/__init__.py
@@ -481,13 +481,14 @@ def _get_config_or_cache_dir(xdg_base_getter):
     tmpdir = os.environ["MPLCONFIGDIR"] = \
         tempfile.mkdtemp(prefix="matplotlib-")
     atexit.register(shutil.rmtree, tmpdir)
-    _log.warning(
-        "Matplotlib created a temporary config/cache directory at %s because "
-        "the default path (%s) is not a writable directory; it is highly "
-        "recommended to set the MPLCONFIGDIR environment variable to a "
-        "writable directory, in particular to speed up the import of "
-        "Matplotlib and to better support multiprocessing.",
-        tmpdir, configdir)
+    if not os.environ.get("MPLNOCACHEWARN"):
+        _log.warning(
+            "Matplotlib created a temporary config/cache directory at %s because "
+            "the default path (%s) is not a writable directory; it is highly "
+            "recommended to set the MPLCONFIGDIR environment variable to a "
+            "writable directory, in particular to speed up the import of "
+            "Matplotlib and to better support multiprocessing.",
+            tmpdir, configdir)

Or, perhaps switch to using the warnings module for the message, and give it a category, then allow people to suppress it via warnings.filterwarnings(category).

@jklymak
Copy link
Member

jklymak commented Sep 23, 2021

You can filter logging module warnings as well: https://docs.python.org/3/library/logging.html

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

Successfully merging a pull request may close this issue.

6 participants