-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
Conversation
…014-on-v3.3.x Backport PR #18014 on branch v3.3.x (Fix flipped paths in non-writable config dir warning.)
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. |
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. |
@tacaswell Is the JSON filename always the same? |
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. matplotlib/lib/matplotlib/font_manager.py Lines 1623 to 1638 in 133f797
|
PR Summary
Fixes #18011.
PR Checklist