OSError: cannot open resource(pillow错误处理)
https://www.jianshu.com/p/c64ae3e9b196
pillow使用备忘之OSError: cannot open resource错误处理
在使用pillow过程中,Python程序出现了:OSError: cannot open resource提示。
File "E:\06_python\python_demo\MyBlog\web\views\account.py", line 89, in test2
img, code = create_validate_code()
File "E:\06_python\python_demo\MyBlog\utils\check_code.py", line 92, in create_validate_code
strs = create_strs()
File "E:\06_python\python_demo\MyBlog\utils\check_code.py", line 80, in create_strs
font = ImageFont.truetype(font_type, font_size)
File "C:\Users\ic\AppData\Local\Programs\Python\Python35\lib\site-packages\PIL\ImageFont.py", line 280, in truetype
return FreeTypeFont(font, size, index, encoding, layout_engine)
File "C:\Users\ic\AppData\Local\Programs\Python\Python35\lib\site-packages\PIL\ImageFont.py", line 145, in __init__
layout_engine=layout_engine)
OSError: cannot open resource
[11/May/2019 15:07:57] "GET /test2.html HTTP/1.1" 500 92941
Performing system checks...
经查此类是常见的字体问题。
在Windows环境,字体一般位于C:\WINDOWS\Fonts文件夹下。用户可以到此文件夹中查看Python程序中指定的字体是否存在。

实践出真知:
字体名称英文大小写要一致;
字体名称是英文的,不是中文。
如简体黑体常规程序中对应的字体名称为simhei.ttf,而简体仿宋常规对应的字体名为simfang.ttf。
Python程序中直接写类似华文行楷.ttf、微软简粗黑.TTF等中文名称的字体会出错。
查看对应字体英文名称的方法很简单,我们可以选中相应字体,右击属性项即可找到。
从此图可以看出,简体华文新魏字体对应的英文名称为:STXINWEI.TTF,这个英文名用于Python程序才正确。
还有另一种情况:
Python程序没有提示出错,但中文文字无法正常显示(中文输出显示成空白方框),则需要更换支持中文的字体。
以上是我实践的结论,可以供临时解决上述出错问题。
但出错背后的机制,我仍未掌握,欢迎高手交流指正。
OSError: cannot open resource(pillow错误处理)的更多相关文章
- 在加载模块时出现cannot insert '*.ko': Device or resource busy错误
制作了一个模块,在加载是出现了cannot insert '*.ko': Device or resource busy错误. 原因: 是由于模块使用的是静态分配设备号,而这个设备号已经被系统中的其他 ...
- captcha库报错"OSError: cannot open resource"
问题描述 在win平台上python虚拟环境下使用captcha库生成验证码报错OSError: cannot open resource 代码 from captcha.image import I ...
- 安装pillow错误的解决方案
错误信息: ValueError: jpeg is required unless explicitly disabled using --disable-jpeg, aborting ...
- Angular中的Error: [$resource:badcfg]错误如何解决之一种
相信这种情况很多的吧,我遇到的情况是因为在作reSource的service时,query出来的协议不对. 错误时候的代码: Version.factory("versionSrv" ...
- docker中执行sed: can't move '/etc/resolv.conf73UqmG' to '/etc/resolv.conf': Device or resource busy错误的处理原因及方式
错误现象 在docker容器中想要修改/etc/resolv.conf中的namesever,使用sed命令进行执行时遇到错误: / # sed -i 's/192.168.1.1/192.168.1 ...
- python使用open的OSError: [Errno 22] Invalid argument错误
这两天在写一个新闻类的spider时,遇到了OSError: [Errno 22] Invalid argument这个错误,苦恼的两天,无果.后来通过请教学长,发现原来是打开的文件名中含有一些系统的 ...
- tomcat服务器-谷歌等浏览器-加载本地图片等资源-报not allowed to load local resource的错误解决办法。
把文件存放路径目录映射到tomcat中,方法如下: 1.找到tomcat的配置文件(\conf\server.xml)并打开 2.在[host]与[/host]之间加入如下代码:[<Contex ...
- PHP 最大化资源配置 Resource Limits 错误两则
报错信息1:PHP Fatal error: Allowed memory size of 25165824 bytes exhausted (tried to allocate 67108888 b ...
- 在 linux 中遇到 OSError: inotify watch limit reached 错误
检查系统当前限制,默认应该是 8192: cat /proc/sys/fs/inotify/max_user_watches 可根据需要调整系统限制,但是目前还不知道如何查看每个进程对 watch 的 ...
随机推荐
- [python]近日 用3种库 实现简单的窗口 的回顾~
最近任务:利用python 实现以下4个窗口弹窗. 信息提示框 文本输入框(需在窗口消失后,返回 用户输入的值) 文件选择(需在窗口消失后, 返回 用户选择的文件名的全路径) 文件夹选择(需在窗口消失 ...
- RPA自定义脚本打开文件夹
import os import subprocess from rpa.web.common.utils import convert_2_unicode def startfile(filenam ...
- docker部署redis
镜像获取 docker pull redis:4.0 ##当前最新版本 docker images 启动 docker run --name redis-huiyuan -p : -v $PWD/da ...
- [转载]目标检测-Selective Search
[转载]目标检测-Selective Search 转载纯粹是因为这篇写的很好,mark一下: https://zhuanlan.zhihu.com/p/27467369
- SqlServer 附加数据库出错
方法一 找到要添加数据库的.mdf文件,点击右键,选择属性 在属性页面点击安全,选择Authenticated Users,单击编辑 Authenticated Users权限中选择完全控制,点击确定 ...
- html与css注意事项及小知识点
html 常用的html特殊符号: 空格:&npsd: 版权所有符号:©: 注册商标符号:®: 有两个标签容器:<span>和<div> ...
- python 修改、读取图片元数据
图片元数据 图片元数据(metadata)是嵌入到图片文件中的一些标签.比较像文件属性,但是种类繁多.常见的几种标准有: EXIF:通常被数码相机在拍摄照片时自动添加,比如相机型号.镜头.曝光.图片尺 ...
- C# Winfrom GDI+ 自定义控件
using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; u ...
- Linux下安装opencv(踩坑记录帖)
1.首先安装依赖项:sudo apt install build-essential sudo apt install build-essentialsudo apt install cmake gi ...
- Protocol handler start failedCaused by: java.net.SocketException: Permission denied
最近在使用mac启动项目的时候,发现原本在Windows下正常跑的项目报错如下: Protocol handler start failedCaused by: java.net.SocketExce ...