如何构建可以使用 Web UI 运行的 python 脚本



我有一个Python脚本,可以创建一个excel文件,其中包含用户从我用一些html页面,css和javascript创建的HTML UI中给出的输入信息。我需要它才能脱机工作,我需要将其分发给客户端。

如何捆绑此 HTML UI 和 Python 文件,以便客户端不需要安装 Python 或任何依赖项即可使用我的应用?我认为eel不需要客户端安装 python 来使用它来完成这项工作,但在 eel 中客户端应该已经安装了 chrome,对吗?

编辑:

我的JS:

function elect() {
console.log('Im in function right now');
let {PythonShell} = require('python-shell');
var path = require('path');
var options = {
scriptPath : path.join(__dirname, '/../engine/')
}
var axiexe = new PythonShell ('test sort.py', options);
axiexe.on('message', function (message) {
swal(message);
})
}

我的目录E:Webtesting my appGUI里面,我有文件夹node_modules@electron, .bin, python-shell等文件夹。

我现在正在开发Python后端提供的Electron应用程序。 我的流程如下: 1. 安装 Pyshell 作为 npm 模块。 2. 创建您的电子用户界面 3. 使用 pyinstaller 编译你的 python 代码。

然后是诀窍。事实上,Pyshell也使用安装在机器上的python。 另一种方法是在Python中运行服务器,我向自己提出了一个问题。如果我有非常微不足道的功能,我为什么要这样做?

溶液: 修改python-shell使其运行exe文件,我也使用了一个技巧,我说python的路径是我的编译python_code.exe 并且我的脚本为空,然后我在 python-shell 中注释了检查脚本长度的行 在 communicator 中.js对于构建版本,请使用:

let options = {
mode: 'text',
pythonPath: "resources/app/python_build/electron_backend.exe"
};
pyshell = new PythonShell(' ', options);

而对于开发,Pyshell将从env.变量中获取您的Python安装。所以我们只需要提供一个.py文件路径

pyshell = new PythonShell('electron_backend.py');

为了使它运行,请更改pyshell模块的源代码,评论如下:

// if (scriptPath.trim().length == 0)
// throw Error("scriptPath cannot be empty! You must give a script for python to run");

最新更新