The PermissionError: [Errno 13] shown while I run the "import matplotlib.pyplot as plt"

Dear all, I want to import the matplotlib.pyplot on jupyter notebook.
I am under Python 3.12.3 | packaged by conda-forge.
Besides, I have already upgraded the version of matplotlib.
However, once I type “import matplotlib.pyplot as plt”, it shown the message “Matplotlib is building the font cache; this may take a moment.”, then following PermissionError message.
At the end of the Perssion Error message, it just said that "PermissionError: [Errno 13] Permission denied: ‘C:\Users\J\.matplotlib\fontlist-v330.json.matplotlib-lock’

I have tries different ways to resolve this problem including uninstall and reinstall my anaconda, python, and upgrade the matplotlib etc.
But the result still keeps the same.
Could anyone give me a hand? A lot of thanks for your kindly help.

1 Like

Can you try deleting C:\Users\J\.matplotlib?

Hello,
As per me to resolve the PermissionError when importing matplotlib.pyplot in Jupyter Notebook, delete the fontlist-v330.json.matplotlib-lock file in C:\Users\J.matplotlib. Ensure you have full control over the .matplotlib folder by adjusting its security settings. Run Anaconda Prompt as an Administrator and launch Jupyter Notebook from there. Alternatively, set the Matplotlib directory by adding import os and os.environ[‘MPLCONFIGDIR’] = os.path.join(os.getenv(‘HOME’), ‘.config’, ‘matplotlib’) before importing matplotlib.

Hi, QuLogic,
Yes, I deleted “C:\Users\J.matplotlib”, then execute the “import matplot.pyplot as plt” again. Then, it works!
I still have no idea about what happens to result the PermissionDenied event now. Since the matplotlib worked smooth before.

Thank you very much for your suggestion!

Dear rileybailey,

Thank you so much for the detail suggestion!
I did the deletion of “C:\Users\J.matplotlib” and open the Jupyter Notebook through Anaconda prompt, then I type and run the "“import matplotlib.pyplot as plt”, then, it works!
Thanks so much for your response.
This is the first time that I meet the PermessionDenied event when I execute the matplotlib, and I still have no idea about it.

Thank you, have a nice day!