Jupyter Hub 解决中文乱码问题

    技术2022-07-13  64

    问题

    在使用matplotlib绘图时,会出现中文变成方框的问题

    解决方法

    找到服务器上jupyter hub中字体存放的路径 import matplotlib print(matplotlib.matplotlib_fname())

    2. 登陆Jupyter Hub 服务器(我的是centos),切换至以下路径

    cd /opt/module/anaconda3/lib/python3.6/site-packages/matplotlib/mpl-data

    3. 进入fonts目录,并下载simhei.ttf

    cd mpl-data/fonts/ttf wget wget http://a.xzfile.com/down3/simhei_downcc.com.zip unzip simhei_downcc.com.zi 修改matplotlibrc文件,在文件末尾加入以下代码 cd ../.. vim matplotlibrc font.family : sans-serif font.sans-serif : SimHei, Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif axes.unicode_minus : False :q! 删除本账户下的缓存文件 cd /home/XXXXX/.cache/matplotlib #把 XXXX 替换成当前使用账户 rm -rf * 重启本账户jupyter hub 服务
    Processed: 0.020, SQL: 9