3

I install matplotlib but python 3.8.10 show me this error.

AttributeError: module 'matplotlib' has no attribute 'font_manager'

What i am doing wrong? enter image description here

import sys
sys.path.append(r'C:\Python38\Lib\site-packages')
sys.path.append(r'C:\Python38\Lib\site-packages\matplotlib')

import matplotlib

system_fonts = matplotlib.font_manager.findSystemFonts(fontpaths=None, fontext='ttf') 
print(dir(system_fonts))
martineau
  • 119,623
  • 25
  • 170
  • 301
Dmitry Dronov
  • 350
  • 3
  • 11

1 Answers1

4

font_manager is a sub-module, and sub-modules aren't imported automatically. Sometimes the __init__.py module will import a sub-module for you, but you can't always count on this.

Import it explicitly:

import matplotlib.font_manager
John Gordon
  • 29,573
  • 7
  • 33
  • 58