在python image 中安装中文字体的实现方法
作者:kozazyh 时间:2021-08-06 06:19:35
如果一些应用需要到中文字体(如果pygraphviz,不安装中文字体,中文会显示乱码),就要在image 中安装中文字体。
默认 python image 是不包含中文字体的:
mac-temp:relation_graph test$ docker run --rm -it python bash
root@36d738e2084c:/# fc-list
/usr/share/fonts/truetype/dejavu/DejaVuSerif-Bold.ttf: DejaVu Serif:style=Bold
/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf: DejaVu Sans Mono:style=Book
/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf: DejaVu Sans:style=Book
/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf: DejaVu Sans:style=Bold
/usr/share/fonts/truetype/dejavu/DejaVuSansMono-Bold.ttf: DejaVu Sans Mono:style=Bold
/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf: DejaVu Serif:style=Book
Dockerfile 如下:
FROM python
RUN apt-get update
RUN apt-get install -y apt-utils dialog xfonts-utils
COPY ./wqy-microhei.ttc /usr/share/fonts/
RUN cd /usr/share/fonts/
RUN mkfontscale && mkfontdir && fc-cache
重新build image
mac-temp:ttc test$ docker build -t ttc:0.0.1 .
检查是否安装成功
mac-temp:ttc test$ docker run --rm -it ttc:0.0.1 bash
root@b1cc465b4ba9:/# fc-list :lang=zh-cn
/usr/share/fonts/wqy-microhei.ttc: WenQuanYi Micro Hei,文泉驛微米黑,文泉驿微米黑:style=Regular
/usr/share/fonts/wqy-microhei.ttc: WenQuanYi Micro Hei Mono,文泉驛等寬微米黑,文泉驿等宽微米黑:style=Regular
其中 wqy-microhei.ttc 字体文件是在其他其他桌面系统上拷贝过来的,可以使用以下方法找到:
mac-temp test$ fc-list :lang=zh-cn
/System/Library/Assets/com_apple_MobileAsset_Font4/2e3dd84241cc7676f2fc8c357c9087fee8cd0075.asset/AssetData/Lantinghei.ttc: 兰亭黑\-简,蘭亭黑\-簡,Lantinghei SC:style=Demibold,中黑
/System/Library/Assets/com_apple_MobileAsset_Font4/8d69c72f04dcc2dfc086aa401dbab7f8ec55d0bb.asset/AssetData/Kaiti.ttc: 楷体\-繁,楷體\-繁,Kaiti TC:style=黑体,黑體,Black
来源:https://blog.csdn.net/kozazyh/article/details/79365706
标签:python,image,安装,中文字体
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python 学习教程之networkx
2023-10-11 01:49:07
好用的JS图片预加载类
2007-08-13 13:49:00
详解Laravel模型事件和模型事件在Trait中的使用
2023-06-17 17:19:28
基于Python实现MUI侧滑菜单a标签跳转
2021-06-12 22:49:22
![](https://img.aspxhome.com/file/2023/1/70851_0s.jpg)
Python爬取知乎图片代码实现解析
2023-02-22 08:14:14
![](https://img.aspxhome.com/file/2023/7/81777_0s.jpg)
一个滑动展示的小代码
2011-07-01 12:58:05
SQL Server转换为XQuery及反向转换
2009-01-20 13:32:00
Dreamweaver制作技巧四则
2008-01-04 09:42:00
python列表去重的二种方法
2022-06-02 05:21:41
python实现textrank关键词提取
2021-11-01 16:47:58
python 安装移动复制第三方库操作
2022-01-20 06:43:09
![](https://img.aspxhome.com/file/2023/9/91919_0s.jpg)
python3使用腾讯企业邮箱发送邮件的实例
2023-09-29 14:31:05
![](https://img.aspxhome.com/file/2023/7/88877_0s.jpg)
2008圣诞节网站特色Logo不完全点评
2008-12-25 18:35:00
![](https://img.aspxhome.com/file/UploadPic/up/1-shengdanjie.jpg)
python3中str(字符串)的使用教程
2021-07-19 00:28:47
Flask的图形化管理界面搭建框架Flask-Admin的使用教程
2023-03-18 07:14:03
Python并发之多进程的方法实例代码
2022-04-13 12:43:54
sqlserver 日期比较、日期查询常用语句:月的第一天,季度的第一天等
2010-08-01 18:58:00
python实现按键精灵找色点击功能教程,使用pywin32和Pillow库
2023-11-08 18:30:34
![](https://img.aspxhome.com/file/2023/5/63915_0s.jpg)
Python线程池thread pool创建使用及实例代码分享
2022-02-26 00:43:35
![](https://img.aspxhome.com/file/2023/9/69569_0s.png)
如何在Windows中安装多个python解释器
2023-08-28 02:55:43
![](https://img.aspxhome.com/file/2023/1/101011_0s.jpg)