MacOSで開発しており、matplotlibの文字化け対応はjapanize_matplotlibで行っています。
この時、ローカル環境ではmatplotlibの文字化けはなく(日本語が□になることなく)表示できるのですが、これをpyinstallerでexe化して実行すると、文字化けしていまします。
文字化けしないようにするには、どのように対応したらいいでしょうか?
python
1import matplotlib.pyplot as plt 2import japanize_matplotlib 3 4plt.figure() 5plt.plot([[1,1], [2,2]]) 6plt.xlabel('日本語テスト') 7plt.legend() 8plt.savefig('tmp.png') 9plt.show()
このとき、pyinstallerでexeファイル化して実行すると、以下のWarningが出て、保存された画像の日本語が文字化けします。
terminal
1No artists with labels found to put in legend. Note that artists whose label start with an underscore are ignored when legend() is called with no argument. 2findfont: Font family ['IPAexGothic'] not found. Falling back to DejaVu Sans. 3test.py:8: UserWarning: Glyph 26085 (\N{CJK UNIFIED IDEOGRAPH-65E5}) missing from current font. 4test.py:8: UserWarning: Glyph 26412 (\N{CJK UNIFIED IDEOGRAPH-672C}) missing from current font. 5test.py:8: UserWarning: Glyph 35486 (\N{CJK UNIFIED IDEOGRAPH-8A9E}) missing from current font. 6test.py:9: UserWarning: Glyph 26085 (\N{CJK UNIFIED IDEOGRAPH-65E5}) missing from current font. 7test.py:9: UserWarning: Glyph 26412 (\N{CJK UNIFIED IDEOGRAPH-672C}) missing from current font. 8test.py:9: UserWarning: Glyph 35486 (\N{CJK UNIFIED IDEOGRAPH-8A9E}) missing from current font.
以下を参考にしてif hasattr...やplt.legend(prop={“family”:”MS Gothic”})の部分を入れても駄目でした。
https://rikei-fufu.com/2019/09/18/post-2071-python-exe/

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/04/15 02:29