Matplotlib.pyplot - AttributeError - type object 'Path' has no attribute 'home'

AttributeError: type object ‘Path’ has no attribute ‘home’

This error message is found while I was trying to from matplotlib.pyplot as plt today. I’ve got NO idea what had happened to my python. But, it seems this issue had been met and solved in some public posts. For instance:

Solutions:

In my case, I need to manually modify 3 files under folder ~/.local/lib/python3.6/site-packages/matplotlib.

Path.home() -> os.path.expanduser(’~’)

  • In file ~/.local/lib/python3.6/site-packages/matplotlib/font_manager.py, around line 135, change
1
2
3
if not USE_FONTCONFIG and sys.platform != 'win32':
OSXFontDirectories.append(str(Path.home() / "Library/Fonts"))
X11FontDirectories.append(str(Path.home() / ".fonts"))

to

1
2
3
if not USE_FONTCONFIG and sys.platform != 'win32':
OSXFontDirectories.append(str(os.path.expanduser('~')+'/'+"Library/Fonts"))
X11FontDirectories.append(str(os.path.expanduser('~')+'/'+".fonts"))

Remove exist_ok=True in function mkdir()

  • In file ~/.local/lib/python3.6/site-packages/matplotlib/init.py, around line 615
  • In file ~/.local/lib/python3.6/site-packages/matplotlib/texmanager.py, around line 56 and 104

change all

1
mkdir(parents=True, exist_ok=True)

to

1
mkdir(parents=True)