LoginSignup
49
29

More than 5 years have passed since last update.

Google Colabでまた日本語表示が豆腐不可避な方に

Last updated at Posted at 2019-01-21

1.想定する読者

  • 以下の記事を見てgoogle colabの日本語化を済ませたのに、また2019年年明けから豆腐に悩まされている皆様(筆者含む)。
  • 尚、上記記事には大変お世話になりました。助かりました。

2.結論:matplotlibがver.3以上だとfont cacheが「fontlist-v300.json」に変更

  • 上記記事にあるようにfont cacheを消しても意味がないです。
  • NG.py
    # このコマンドだと豆腐不可避
    rm /root/.cache/matplotlib/fontList.json
    
  • matplotlibのcacheに-v300と書いてある見慣れないファイル、これが本来消すべきfont cacheです。

ls.py
!ls -ll /root/.cache/matplotlib/
-rw-r--r-- 1 root root 46110 Jan 17 17:06 fontList.json
-rw-r--r-- 1 root root 29351 Jan 17 17:06 fontlist-v300.json # これが目標物です
drwxr-xr-x 2 root root  4096 Jan 17 17:06 tex.cache
  • 執筆時点(2019年1月)でgoogle colabにデフォルトでインストールされているmatplotlibのVersioonは3.0以上になっており、cacheファイルが変更になっています。
pipfreeze.py
!pip freeze
~(中略)~
matplotlib==3.0.2 # バージョンが3以上
~(中略)~

3.matplotlib ver.3以降の新たな日本語表示手順

success.py
# 日本語フォントをダウンロードする。
!apt-get -y install fonts-ipafont-gothic

# キャッシュを削除する。
# !rm /root/.cache/matplotlib/fontList.json # 旧cache
!rm /root/.cache/matplotlib/fontlist-v300.json # 消すべきcache

# ランタイムを再起動する。
  • 削除するキャッシュさえ間違わなければ解決できます。

4.before-after

  • 旧手順。相変わらず豆腐まみれです。
    qiita20190121b.PNG

  • 新手順。豆腐が解消されています。
    qiita20190121a.PNG

以上です。

49
29
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
49
29