目录简介安装 enchant 模块模块使用demo使用PyInstaller打包成exe文件运行时找不到字典库简介enchant是 Python 的拼写检查库封装系统本地拼写检查引擎hunspell、aspell 等用来做单词拼写校验、纠错建议、多语言词典。安装 enchant 模块pip install pyenchant-i https://pypi.tuna.tsinghua.edu.cn/simple为了保证 en_US 等词典能被 python 识别到不要使用从 windows系统 应用商店下载的版本不然会被限制导致无法识别到词典模块使用demofrom enchant.checker import SpellChecker chkrSpellChecker(en_US)# 创建字典实例 chkr.set_text(This is sme sample txt with erors.)forerr in chkr:print(error: ,err.word)# 输出#error:sme#error:txt#error:erors# 检查单词拼写print(d.check(Hello))# Trueprint(d.check(Helo))# False使用PyInstaller打包成exe文件运行时找不到字典库问题核心原因enchant库的字典文件如en_US.dic是外部资源文件PyInstaller无法自动识别和包含这些文件导致打包后的EXE运行时找不到字典库。解决方法修改spec文件编辑生成的.spec文件在datas部分添加字典文件路径。返回 Python专栏目录及索引