首页 > 解决方案 > 如何在电子生成器构建中包含 python 文件?

问题描述

我正在使用 electron-builder 从 electronjs 构建一个应用程序(获取可安装的 .exe)。问题是在编译并启动程序后,在控制台中我收到以下消息:

C:\Users\User\anaconda3\python.exe: can't open file 
'C:\Users\User\Desktop\ProxyChecker\gui\dist\win-unpacked\resources\app.asar\ProxyChecker.py': [Errno 2] No such file or directory

我在构建之前的文件夹结构如下所示:

/node_modules
/linkers --> linker.js
.gui.html
.main.js
.package.json
.preload.js
.ProxyChecker.py
.renderer.js

据我了解,问题出在 package.json 配置中。看起来像这样:

{
  "name": "electron-quick-start",
  "version": "1.0.0",
  "description": "A minimal Electron application",
  "main": "main.js",
  "scripts": {
    "start": "electron .",
    "build-installer": "electron-builder"
  },
  "build": {
    "extraResources": [
      {
        "from": "/",
        "to": "" 
      }
    ],
    "appId": "electron-quick-start",
    "win": {
      "target": ["nsis"]
    },
    "nsis": {
      "uninstallDisplayName": "electron-quick-start",
      "oneClick": false,
      "allowToChangeInstallationDirectory": true
    },
    "files": [
      "ProxyChecker.py",
      "**/*"
    ]
  },
  "repository": "https://github.com/electron/electron-quick-start",
  "keywords": [
    "Electron",
    "quick",
    "start",
    "tutorial",
    "demo"
  ],
  "author": "GitHub",
  "license": "CC0-1.0",
  "devDependencies": {
    "electron": "^11.2.1",
    "electron-packager": "^15.2.0"
  },
  "dependencies": {
    "python-shell": "^0.4.0"
  },
  "asar": true,
    "asarUnpack": [
      "ProxyChecker.py"
    ]
}

我尝试过的事情:

这些都没有帮助。

谢谢你的帮助。

标签: pythonelectronelectron-builder

解决方案


推荐阅读