–by DeadWood8

打包环境

  • OS: Windows11
  • Python: 3.8.10
  • rapidocr_onnxruntime: 1.2.0
  • nuitka: 1.5.3
  • onnxruntime: 1.14.0

打包步骤

  1. 安装Nuitka

      pip install nuitka
      

    注:第一次安装会自动下载mingw和ccache,也可以手动配置,自行某度。

  2. 修改rapidocr-onnxruntime源码(修改后可以将所有依赖打包进文件)

    • 进入rapidocr-onnxruntime安装位置,一般在Lib\site-packages\rapidocr_onnxruntime或者你设置的虚拟环境下。
    • 用编辑器打开rapid_ocr_api.py,对39-52行进行修改,如下图:

    image

  3. nuitka打包

      cd rapidocr_web
    nuitka --mingw64 --standalone --show-memory --show-progress --nofollow-import-to=tkinter --output-dir=out ocrweb.py
      
    • 如下图所示:

    image

  4. 拷贝静态文件

    • 打包后的文件位于当前位置的out\ocrweb.dist目录下,需要将web项目和rapidocr-onnxruntime相关文件拷贝到此目录。

    image

    • 拷贝rapidocr_web目录statictemplates两个文件夹全部拷贝到out\ocrweb.dist
    • out\ocrweb.dist创建rapidocr_onnxruntime文件夹,将Lib\site-packages\rapidocr_onnxruntime目录下的config.yamlmodels文件夹拷贝到out\ocrweb.dist\rapidocr_onnxruntime文件夹内
  5. 运行程序

    • 进入out\ocrweb.dist,直接双击ocrweb.exe运行。

    image

  6. 打包好的exe下载:百度网盘 | Google Drive | Gitee

补充

  • 如果不想运行程序后有黑框,可以在打包命令中加入以下参数 --windows-disable-console
  • 完整命令为:
      nuitka --mingw64 --standalone --show-memory --show-progress --nofollow-import-to=tkinter --windows-disable-console --output-dir=out ocrweb.py
      

Last updated 24 Apr 2024, 09:27 +0800 . history