matplotlib を、matplotlib (1.3.1) から、matplotlib (2.0.2) に upgrade した際に、発生した問題とその解決方法を記載します。


前提

OS 、 python の version 情報は以下になります。

  • OS

    % sw_vers 
    ProductName:    Mac OS X
    ProductVersion: 10.12.6
    BuildVersion:   16G29
    

  • python

    % python -V
    Python 2.7.10
    


何故 upgrade しようと思ったか

matplotlib.pyplot.show() で、FutureWarning が発生しておりました。
いい加減毎回出力されるのがうざいので、upgrade を実施しました。
出力 Warning は以下の内容でした。

/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/collections.py:608: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
  if self._edgecolors_original != 'face':


pip で upgrade を実施する

とりあえず、upgrade すれば消えるだろうと、

% sudo pip install -U matplotlib
コマンド実行したところ、以下 Error が出力されました。
  Found existing installation: pyparsing 2.0.1
    DEPRECATION: Uninstalling a distutils installed project (pyparsing) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
    Uninstalling pyparsing-2.0.1:
以下の通り、upgrade 自体も失敗していたため、
% sudo pip list | grep matplotlib
matplotlib (1.3.1)
python - Error in pip install matplotlib in Mac - Stack Overflow参考に、six install 対象外にして、再度 pip を実行しました。
sudo pip install matplotlib --upgrade --ignore-installed six
無事、upgrade が成功し、version は matplotlib (2.0.2)なりました。
% pip list | grep matplotlib
matplotlib (2.0.2)

Error 自体は何か見たことあると思ったんですが、
pandas を upgrade して 同じエラーに同じくsix install 対象外にして対処していました。。

mac os sierra の pandas を upgrade したら [Errno 1] Operation not permitted:発生 | Monotalk


Font cache を削除する

upgrade 後にスクリプトを実行すると以下のWarning が出力されました。

/Library/Python/2.7/site-packages/matplotlib/font_manager.py:280: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment.
  'Matplotlib is building the font cache using fc-list. '
同様の問題にぶつかっている方がいて、そちらを参考に Cache 削除を実施しました。 matplotlib】import matplotlibでfont cacheについてUserWarningが出る場合 – 青の弾丸


Font が 見つからず、デフォルトのFont が使われる

グラフ描画時に使用しているFont が見つからないというWarning が出力されるようになりました。
これは、指定していたFontがそもそも元々見つかっておらず、Upgrade によりメッセージが出力されるようになった、
しくは、Font cache には存在していたが消したので見つからないのいずれかかと思います。

/Library/Python/2.7/site-packages/matplotlib/font_manager.py:1297: UserWarning: findfont: Font family [u'Yu Gothic'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))
こちらは、Macにおけるmatplotlibの日本語表示 | OpenBook参考に使用可能な日本語Fontを指定するようにしました。

Error で落ちないまでも、警告はいろいろでますね。
以上です。

コメント