guaguastandup/zotero-pdf2zh

将python脚本整合入Pdf2zh WinEXE中

Open

#201 ouverte le 5 nov. 2025

Voir sur GitHub
 (1 commentaire) (0 réactions) (0 assignés)Python (177 forks)auto 404
enhancementgood first issue

Métriques du dépôt

Stars
 (4 420 stars)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

Description

首先非常感谢贡献者开发的本插件!我注意到当前的脚本服务端通常依赖于uv或conda虚拟环境,因此在初次脚本运行时需要构建依赖,这既费时也占用存储空间,同时贡献者需要花费精力维护这方面的代码。

此外,我注意到pdf2zh_next 贡献者发布了一个Windows EXE版本,可以直接在Windows以EXE程序进行运行,基本贴合用户的使用习惯。

考察该程序,其本质上是利用了Pystand的方法,通过构建一个空壳应用,转发启动同目录下的脚本,因此我建议贡献者可以按照以下方法将服务端脚本整合入Pdf2zh WinEXE中,发布集成脚本,仅需通过与pdf2zh_next 相同的EXE程序启动.

一种简单实现思路如下:

  1. 下载pdf2zh-v2.6.4-BabelDOC-v0.5.14-with-assets-win64.zip并解压;
  2. 将下载文件目录下的_pystand_static.int重命名为 pdf2zh_next.int,这样将使得pdf2zh_next.exe查找启动对象改为pdf2zh_next.int,避免后续启动冲突;
  3. 复制pdf2zh_next.exe并将一份重命名为zotero_pdf2zh_console.exe
  4. 在文件目录下创建新的int文件(文件名:zotero_pdf2zh_console.int),包含以下内容:
import sys
import zotero_pdf2zh.server
import os
import babeldoc.assets.assets
import pathlib
import asyncio
import multiprocessing

WAIT_FOR_INPUT = False
if len(sys.argv) == 1:
    sys.argv.append("--gui")  # 无参数时自动添加 -i 参数
    WAIT_FOR_INPUT = True

multiprocessing.set_executable(os.path.join(os.path.dirname(__file__), 'runtime', 'pythonw.exe'))

files = os.listdir(os.path.dirname(__file__))

try:
    code = asyncio.run(zotero_pdf2zh.server.main())
    print(f"pdf2zh_next.server.main() return code: {code}")
    if WAIT_FOR_INPUT:
        input("Press Enter to continue...")
    sys.exit(code)
except Exception:
    import traceback
    traceback.print_exc()
    if WAIT_FOR_INPUT:
        input("Press Enter to continue...")
    sys.exit(1)
  1. 将服务端脚本需要的依赖库添加到site-packages中
  2. 将服务端脚本以库的形式放置在site-packages\zotero_pdf2zh文件下 ,文件夹下包含utils文件夹和server.py文件

上述方法与原应用类似,即创建一个新的插件启动终端的套壳,用户只需启动exe文件即可启动服务端脚本了。 注意,应当在server.py中进行修改,去除关于环境部署相关内容同时对更新代码稍作修改。zotero_pdf2zh.server.main()包含启动服务类PDFTranslator的实例化方法即可。

此致,再次感谢贡献者无私付出!

Guide contributeur