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

Skip to content

Fix flipped paths in non-writable config dir warning. #18014

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

Merged
merged 1 commit into from
Jul 22, 2020

Conversation

QuLogic
Copy link
Member

@QuLogic QuLogic commented Jul 22, 2020

PR Summary

Fixes #18011.

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/next_api_changes/* if API changed in a backward-incompatible way

@QuLogic QuLogic added this to the v3.3.1 milestone Jul 22, 2020
@jklymak jklymak merged commit 9fcf958 into matplotlib:master Jul 22, 2020
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Jul 22, 2020
@QuLogic QuLogic deleted the fix-non-writable-config branch July 22, 2020 19:54
QuLogic added a commit that referenced this pull request Jul 22, 2020
…014-on-v3.3.x

Backport PR #18014 on branch v3.3.x (Fix flipped paths in non-writable config dir warning.)
@john-zenden
Copy link

john-zenden commented Aug 12, 2022

Error: [WARNING] 2022-08-01T20:35:34.010Z Matplotlib created a temporary config/cache directory at /tmp/matplotlib-dw7qh4b1 because the default path (/home/sbx_user1051/.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.

I got this in AWS Lambda and comment here only for the benefit of those who might come across this in a Google search.

If you are using Matplotlib (or something which depends on it) in the AWS Lambda environment you have probably already run up against 250MB limit for the Zip deployment method of the AWS Lambda function. If you go to a Image deployment, your image can be up to 10GB.

Deploying the AWS Lambda function as an image offers two things to solve this error (and speed up your function). First, in the Configuration section for the function, set the Ephemeral Storage to a higher value (something like 1024). Be aware that your costs will be calculated at GB/seconds for this resource. Then, add the following to your Dockerfile after the RUN command calling pip to install your dependencies:

ENV MPLCONFIGDIR=/tmp

If you look carefully at the Ephemeral Storage setting in AWS, you'll see it refers to /tmp. You are telling Matplotlib to use /tmp as its temp storage, and configuring the max size in AWS at 1GB (1024MB). To see why this works, bring up a CLI for the Docker image. I am developing on Windows with VSCode with the AWS SAM CLI, which requires Docker be installed. So after running > 'sam build' at the Terminal CLI in VSCode, Docker starts running the image. In Docker I click the ">" button and a CLI terminal for the image appears.

Like any other Linux environment, you'll be in a user directory. CD back to the root folder. Do an ls -al and take note of the permissions for /home and /tmp. You'll see that /tmp is writable by default, but /home is not. By adding the ENV command in Dockerfile you are telling Matplotlib to use /tmp. By setting the Ephemeral Storage value in AWS you are allocating sufficient space in /tmp.

Thew warning in the logs should then disappear.

@tacaswell
Copy link
Member

One of the things that goes into the cache directory is a json file of the fonts we found. Pre-generating that file and uncluding it in your image will speed up the initial import time by avoid a (possibly expensive) file walking process.

@john-zenden
Copy link

@tacaswell Is the JSON filename always the same?

@tacaswell
Copy link
Member

Yes, but if we change the spec of the file we will change the filename. We have not changed it recently, but I suspect we will change it soon. If you need to support more than one version of mpl include both files.

def _load_fontmanager(*, try_read_cache=True):
fm_path = Path(
mpl.get_cachedir(), f"fontlist-v{FontManager.__version__}.json")
if try_read_cache:
try:
fm = json_load(fm_path)
except Exception:
pass
else:
if getattr(fm, "_version", object()) == FontManager.__version__:
_log.debug("Using fontManager instance from %s", fm_path)
return fm
fm = FontManager()
json_dump(fm, fm_path)
_log.info("generated new fontManager")
return fm

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 this pull request may close these issues.

Confusing error message when home config directory not writable
4 participants