Setting Matplotlib MPLCONFIGDIR: consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data

后端 未结 3 1318
野的像风
野的像风 2020-12-17 21:10

I am using Linux server to set up a django project. I got this error: \"Failed to create /var/www/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matp

3条回答
  •  有刺的猬
    2020-12-17 21:54

    Set the MPLCONFIGDIR in code before you import matplotlib. Make sure the directory has permissions such that it can be written to by the app.

    import os
    os.environ['MPLCONFIGDIR'] = "/home/lab/website/graph"
    import matplotlib
    

    Alternatively, you could set it to a tempfile.

    import os    
    import tempfile
    os.environ['MPLCONFIGDIR'] = tempfile.mkdtemp()
    import matplotlib
    

提交回复
热议问题