使用pyinstaller打包了一下文件(pyinstaller -F -n test.exe test.py),运行test.exe报错
Traceback (most recent call last): File "ocr识别-服务型版本.py", line 1, in <module> File "<frozen importlib._bootstrap>", line 983, in _find_and_load File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 677, in _load_unlocked File "PyInstaller\loader\pyimod03_importers.py", line 540, in exec_module File "cnocr\__init__.py", line 1, in <module> File "<frozen importlib._bootstrap>", line 983, in _find_and_load File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 677, in _load_unlocked File "PyInstaller\loader\pyimod03_importers.py", line 540, in exec_module File "cnocr\cn_ocr.py", line 21, in <module> File "<frozen importlib._bootstrap>", line 983, in _find_and_load File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 677, in _load_unlocked File "PyInstaller\loader\pyimod03_importers.py", line 540, in exec_module File "mxnet\__init__.py", line 24, in <module> File "<frozen importlib._bootstrap>", line 983, in _find_and_load File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 677, in _load_unlocked File "PyInstaller\loader\pyimod03_importers.py", line 540, in exec_module File "mxnet\context.py", line 24, in <module> File "<frozen importlib._bootstrap>", line 983, in _find_and_load File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 677, in _load_unlocked File "PyInstaller\loader\pyimod03_importers.py", line 540, in exec_module File "mxnet\base.py", line 214, in <module> File "mxnet\base.py", line 204, in _load_lib File "mxnet\libinfo.py", line 74, in find_lib_path RuntimeError: Cannot find the MXNet library. List of candidates: C:\Users\NETPR1~1\AppData\Local\Temp\_MEI270842\mxnet\libmxnet.dll C:\Users\NETPR1~1\AppData\Local\Temp\_MEI270842\mxnet\../../lib/libmxnet.dll C:\Users\NETPR1~1\AppData\Local\Temp\_MEI270842\mxnet\../../build/libmxnet.dll C:\Users\NETPR1~1\AppData\Local\Temp\_MEI270842\mxnet\../../build\libmxnet.dll C:\Users\NETPR1~1\AppData\Local\Temp\_MEI270842\mxnet\../../build\Release\libmxnet.dll C:\Users\NETPR1~1\AppData\Local\Temp\_MEI270842\mxnet\../../windows/x64\Release\libmxnet.dll [564] Failed to execute script ocr识别-服务型版本
在网上找了很多资料,很难呀,博客比较少,就顺便写下来了。
看上面运行的报错信息,明细是缺少了mxnet (已经用红字表明),有可能是pyinstaller 没有识别到mxnet,或者是其他的问题。
解决办法:
1. 重启电脑。 有可能是pyinstaller没有找到mxnet这个包,如果你是刚安装了pyinstaller没重启的话可以一试。
2.在打包程序的时候主动添加缺少的文件包
我这里缺少了mxnet,首先我就要去找到mxnet包的地方,我这里是 :C:\Users\netpr1s0ner\AppData\Local\Programs\Python\Python37\Lib\site-packages\mxnet
然后再打包程序的时候这样输入:pyinstaller -F -n test.exe --add-data="C:\Users\netpr1s0ner\AppData\Local\Programs\Python\Python37\Lib\site-packages\mxnet\*;./mxnet" test.py
(如果不理解这句话是啥意思,先去百度一下 --add-data 参数格式,我这里懒得写了)
之后就可以正常运行了。
总结:缺少什么包就去添加什么包,一般这种方案都可以解决缺少包引发的错误问题。