记录一下解决过程,解决方案耗时6h。
因为公司需要递交完整的分析过程,需要将notebook导出为pdf作为材料,但是国内是不可能避免使用中文路径或者注释的。
默认安装的jupyter和nbconvert、pandoc
xetex是不认中文的。
参考了以下内容,做了一个docker容器,专用于导出pdf。
github
ubuntu论坛
简书
由于各个参考答案和docker总是有那样这样的问题,所以调试也费了一番周折,最后要做以下工作
1、找一个中文字体文件.ttf,案例用的msyh.ttf,重建系统字体索引
2、修改nbconvert的base.tplx与article.tplx,容器内则是直接替换
3、写好dockerfile,构建镜像
整个所需的工具包在csdn资源里
如果404是表示在审核
FROM python:3
WORKDIR /DataScience
RUN cp -a /etc/apt/sources.list /etc/apt/sources.list.bak
COPY ./sources.list /etc/apt/sources.list
RUN apt-get install apt-transport-https ca-certificates -y
RUN apt-get update
COPY ./*.ttf /usr/share/fonts/
RUN fc-cache -f -v
RUN apt-get install pandoc texlive-xetex -y
RUN apt-get install inkscape -y
RUN pip install --trusted-host https://mirrors.huaweicloud.com -i https://mirrors.huaweicloud.com/repository/pypi/simple jupyterlab numpy numba scipy pandas matplotlib nbconvert --no-cache-dir
COPY ./*.tplx /usr/local/lib/python3.8/site-packages/nbconvert/templates/latex/
EXPOSE 8888
CMD jupyter lab --no-browser --ip='0.0.0.0' --allow-root