pyinstaller 打包 paddleocr

一、场景

我们在使用pyinstaller打包完以后,在执行时会出现一些第三方库找不到,尤其是paddleocr库

二、解决方法

在打包paddleocr的时候,他的一些模块不会跟着一起打包,我们要使用已下方法来进行打包处理
  1. 一般情况下打包
pyinstaller -F my_main.py
因为我们程序中使用了paddleocr库,所有这样打包是不行的要在后面加上 --add-data="需要打包的文件目录"
pyinstaller -F my_main.py --add-data="C:\\Users\\dell\\.conda\\envs\\py3.7.3\\Lib\\site-packages\\Shapely.libs;./Shapely.libs"
要是有多个的话就在后面累加
pyinstaller -F my_main.py --add-data="C:\\Users\\dell\\.conda\\envs\\py3.7.3\\Lib\\site-packages\\Shapely.libs;./Shapely.libs" --add-data="C:\\Users\\dell\\.conda\\envs\\py3.7.3\\Li
b\\site-packages\\paddle;./paddle" --add-data="C:\\Users\\dell\\.conda\\envs\\py3.7.3\\Lib\\site-packages\\paddleocr;./paddleocr" --add-data="C:\\Users\\dell\\.conda\\envs\\py3.7.3\\Lib\\site-packages\\PIL;./PIL" --add-data="C:
\\Users\\dell\\.conda\\envs\\py3.7.3\\Lib\\site-packages\\pywt;./pywt" --add-data="C:\\Users\\dell\\.conda\\envs\\py3.7.3\\Lib\\site-packages\\lmdb;./lmdb" --add-data="C:\\Users\\dell\\.conda\\envs\\py3.7.3\\Lib\\site-packages\
\shapely;./shapely" --add-data="C:\\Users\\dell\\.conda\\envs\\py3.7.3\\Lib\\site-packages\\skimage;./skimage" --add-data="C:\\Users\\dell\\.conda\\envs\\py3.7.3\\Lib\\site-packages\\pyclipper;./pyclipper" --add-data="C:\\Users
\\dell\\.conda\\envs\\py3.7.3\\Lib\\site-packages\\scipy;./scipy" --add-data="C:\\Users\\dell\\.conda\\envs\\py3.7.3\\Lib\\site-packages\\imgaug;./imgaug" --add-data="C:\\Users\\dell\\.conda\\envs\\py3.7.3\\Lib\\site-packages\\imageio;./imageio" --add-data="C:\\Users\\dell\\.conda\\envs\\py3.7.3\\Lib\\site-packages\\attrdict;./attrdict"
  1. 如果打包后还有问题,比如:No module named ‘imghdr’,解决方法如下
    找到打包之后的缓存文件 my_main.spec,在hiddenimports列表中添加没有命名的模块
    pyinstaller 打包 paddleocr_第1张图片
    再次进行打包,注意:接下来打包就是从缓存文件中进行了
pyinstaller my_main.spec

如果还是不行就将已下代码添加到缓存文件的最上方

import sys ; sys.setrecursionlimit(sys.getrecursionlimit() * 5)

pyinstaller 打包 paddleocr_第2张图片

你可能感兴趣的:(python,pyinstaller)