【问题标题】:MPLCONFIGDIR error in matplotlibmatplotlib 中的 MPLCONFIGDIR 错误
【发布时间】:2011-04-29 14:50:47
【问题描述】:

当我尝试导入 matplotlib.pyplot 时出现以下错误:

RuntimeError("'%s' is not a writable dir; you must set %s/.matplotlib to be a writable dir.  You can also set environment variable MPLCONFIGDIR to any writable directory where you want matplotlib data stored "% (h, h))

我的主目录中确实有一个 .matplotlib 目录,该目录归我所有并具有写入权限。那么为什么它告诉我它是“不可写的目录”,我该如何解决这个问题?

【问题讨论】:

  • 异常的最终输出是什么?即类似RuntimeError: '/home/ranjit' is not a writable dir; you must set /home/ranjit/.matplotlib to be a writable dir. You can also set environment variable MPLCONFIGDIR to any writable directory where you want matplotlib data stored
  • 是的,%s 是我的主目录。所以它绝对是可写的。
  • ls -ld ~/.matplotlib的输出是什么
  • 好的,问题解决了。其实这很愚蠢。磁盘已满,这就是为什么它报告我的主目录不可写。
  • 搞笑,我也遇到了同样的问题...解决方案:下载数据集时要小心

标签: python matplotlib


【解决方案1】:

不要以 root 身份运行 Python;它不是很安全,您以后可能会遇到更多权限问题。相反,只需确保您拥有主目录和 matplotlib 目录:

sudo chown $USER ~ ~/.matplotlib

【讨论】:

    【解决方案2】:

    MPLCONFIGDIR 设置为“/tmp/”,如this guide 中所述

     # python
     os.environ[ 'MPLCONFIGDIR' ] = '/tmp/'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-02
      • 2018-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-11
      • 2015-12-17
      相关资源
      最近更新 更多