【electron-vue+python】electron启动调用python打包的exe

【electron-vue+python】electron启动调用python打包的exe


一、python打包成exe

pip3 install pyinstaller
打开cmd进入python项目目录下,假设main.py为主程序,执行命令
pyinstaller-F main.py

-F:覆盖打包,打包多次依旧是最新的exe文件

然后在项目目录下会生成 dist 文件夹,dist文件夹里就存放着打包的main.exe
在这里插入图片描述
在这里插入图片描述

二、electron-vue调用python打包的exe文件

1、用cmd进入electron-vue项目目录,安装child_process模块

npm install child_process

2、打开src/main/index.js文件(也就是设置app.on(‘ready’,createWindow) 项目启动的文件)

const {
    
     spawn } = require('child_process')

# main.exe放在了项目根目录下
mainWindow.webContents.on('did-finish-load',() => {
    
    
    const child = spawn('main.exe') 
    child.on('error',(err) => {
    
    
      console.log('err => ',err)
    })
})

关于webContents的解释具体可以在官网查阅了解。


猜你喜欢

转载自blog.csdn.net/weixin_45671901/article/details/130247399