LoginSignup
0
0

japanize_matplotlibがPython 3.12以降`ModuleNotFoundError`で動かない時の対処法

Posted at

問題点と原因

ModuleNotFoundError: No module named 'distutils'

原因: distutilsモジュールがPython 3.12では削除されたから。

解決法の提案

distutilsの代わりにpackagingモジュールを使うようにjapanize_matplotlib本体のソースをいじります。

japanize_matplotlib/japanize_matplotlib.py
import matplotlib
from matplotlib import font_manager
- from distutils.version import LooseVersion
+ from packaging.version import parse as parse_version

FONTS_DIR = 'fonts'
FONT_NAME = "IPAexGothic"
FONT_TTF = 'ipaexg.ttf'


def japanize():
    font_dir_path = get_font_path()
    font_dirs = [font_dir_path]
    font_files = font_manager.findSystemFonts(fontpaths=font_dirs)
-   is_support_createFontList = LooseVersion(matplotlib.__version__) < '3.2'
+   is_support_createFontList = parse_version(matplotlib.__version__) < parse_version('3.2')
    if is_support_createFontList:
        font_list = font_manager.createFontList(font_files)
        font_manager.fontManager.ttflist.extend(font_list)

この件について、issueを立ててPRを送っていますが、作者様からの今のところ返答はありません。

有志が対応した版リリースしているので、こちらを使っても良いかもしれません。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0