Skip to content

Importing pyplot crashes on macOS due to missing fontlist-v300.json and then Permission denied: '/opt/local/share/fonts' #12291

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

Closed
Sparen opened this issue Sep 26, 2018 · 4 comments · Fixed by #12448
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Milestone

Comments

@Sparen
Copy link

Sparen commented Sep 26, 2018

Bug report

This bug was opened in response to a comment on Bug #12176

When importing pyplot on macOS High Sierra with Python 3.6.5 and matplotlib 3.0.0, fontlist-v300.json cannot be found and at the conclusion of the resulting search, permission is denied via Permission denied: '/opt/local/share/fonts'.

Code for reproduction

import matplotlib.pyplot

Actual outcome

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/font_manager.py", line 1353, in <module>
    fontManager = json_load(_fmcache)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/font_manager.py", line 888, in json_load
    with open(filename, 'r') as fh:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/andrewfan/.matplotlib/fontlist-v300.json'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/pyplot.py", line 32, in <module>
    import matplotlib.colorbar
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/colorbar.py", line 32, in <module>
    import matplotlib.contour as contour
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/contour.py", line 18, in <module>
    import matplotlib.font_manager as font_manager
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/font_manager.py", line 1363, in <module>
    _rebuild()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/font_manager.py", line 1344, in _rebuild
    fontManager = FontManager()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/font_manager.py", line 978, in __init__
    ttffiles = findSystemFonts(paths) + findSystemFonts()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/font_manager.py", line 270, in findSystemFonts
    fontfiles.update(OSXInstalledFonts(fontext=fontext))
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/font_manager.py", line 218, in OSXInstalledFonts
    for directory in directories
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/font_manager.py", line 220, in <listcomp>
    for path in list_fonts(directory, ext)]
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/font_manager.py", line 157, in list_fonts
    for path in filter(Path.is_file, Path(directory).glob("**/*.*"))
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/font_manager.py", line 156, in <listcomp>
    return [str(path)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/pathlib.py", line 1098, in glob
    for p in selector.select_from(self):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/pathlib.py", line 487, in select_from
    if not is_dir(parent_path):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/pathlib.py", line 1346, in is_dir
    return S_ISDIR(self.stat().st_mode)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/pathlib.py", line 1156, in stat
    return self._accessor.stat(self)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/pathlib.py", line 387, in wrapped
    return strfunc(str(pathobj), *args)
PermissionError: [Errno 13] Permission denied: '/opt/local/share/fonts'

Expected outcome

Expected outcome is for pyplot to be imported successfully

Matplotlib version

  • Operating system: macOS High Sierra 10.13.6
  • Matplotlib version: 3.0.0
  • Matplotlib backend (print(matplotlib.get_backend())):
  • Python version: 3.6.5
  • Jupyter version (if applicable): N/A (crashes both in Jupyter and in the plain old shell)
  • Other libraries:

matplotlib was installed using pip3.

Running matplotlib.__version__ outputs '3.0.0'

@anntzer
Copy link
Contributor

anntzer commented Sep 26, 2018

This is due to the combination of #10871 + https://bugs.python.org/issue34807. We didn't have this issue before because we relied on os.walk which silently ignores PermissionErrors (and other stat failures).

I guess the fix would basically be to revert #10871 (or relying on glob.glob(directory + "**/*.*") which can theoretically give spurious results if directory happens to contain globbing metacharacters, heh...)... or just implement #10932 instead.

@Sparen
Copy link
Author

Sparen commented Sep 26, 2018

After some conversations it seems that this only occurs in 3.0.0 since 2.2.3 (running on Python 2.7.15) does not exhibit this issue. Does that mean that this issue is considered a regression?

@jklymak jklymak added this to the v3.0.x milestone Sep 26, 2018
@jklymak jklymak added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Sep 26, 2018
@PGTBoos
Copy link

PGTBoos commented Oct 5, 2018

well on windows 10 i had this same error as well, (couldnt find this bugID back) i wrote a fix that worked on Windows see #12406

@hervenivon
Copy link

I have the same problem. Reverting to 2.2.3 "solved" that issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants