matplotlib导入对字体的Python3权限被拒绝

时间:2018-10-04 12:56:24

标签: matplotlib fonts python-3.6

当我尝试导入matplotlib时出现错误。当我以root身份运行我的代码时,不会发生该错误。似乎他在错误的位置搜索字体,因为根目录中没有字体目录。

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/font_manager.py", line 1353, in <module>
    fontManager = json_load(_fmcache)
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/font_manager.py", line 888, in json_load
    with open(filename, 'r') as fh:
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/matplotlib-k04ilz1_/fontlist-v300.json'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test.py", line 1, in <module>
    import matplotlib.pyplot as plt
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/pyplot.py", line 32, in <module>
    import matplotlib.colorbar
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/colorbar.py", line 32, in <module>
    import matplotlib.contour as contour
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/contour.py", line 18, in <module>
    import matplotlib.font_manager as font_manager
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/font_manager.py", line 1363, in <module>
    _rebuild()
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/font_manager.py", line 1344, in _rebuild
    fontManager = FontManager()
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/font_manager.py", line 978, in __init__
    ttffiles = findSystemFonts(paths) + findSystemFonts()
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/font_manager.py", line 276, in findSystemFonts
    fontfiles.update(map(os.path.abspath, list_fonts(path, fontexts)))
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/font_manager.py", line 157, in list_fonts
    for path in filter(Path.is_file, Path(directory).glob("**/*.*"))
  File "/usr/local/lib/python3.6/dist-packages/matplotlib/font_manager.py", line 156, in <listcomp>
    return [str(path)
  File "/usr/lib/python3.6/pathlib.py", line 1098, in glob
    for p in selector.select_from(self):
  File "/usr/lib/python3.6/pathlib.py", line 487, in select_from
    if not is_dir(parent_path):
  File "/usr/lib/python3.6/pathlib.py", line 1346, in is_dir
    return S_ISDIR(self.stat().st_mode)
  File "/usr/lib/python3.6/pathlib.py", line 1156, in stat
    return self._accessor.stat(self)
  File "/usr/lib/python3.6/pathlib.py", line 387, in wrapped
    return strfunc(str(pathobj), *args)
PermissionError: [Errno 13] Permission denied: '/root/.fonts'

0 个答案:

没有答案