我正在尝试在Linux上打包一个带有angular-electron的python二进制可执行文件。我遵循了堆栈溢出中的这个答案。bundling precompiled binary into electron app。
在main.ts中,我编写了这个额外的代码片段。我将可执行二进制文件放在node_modules/datapod/datapod中,并将此路径符号链接到node_modules/.bin/文件夹中。
const spawn = require('child_process').spawn;
var appRootDir = require('app-root-dir').get();
var datapodpath=appRootDir+'/node_modules/datapod/datapod';
console.log(datapodpath)
const datapod = spawn(datapodpath, [], {}); //add whatever switches you need here
datapod.stdout.on( 'data', data => {
console.log( `stdout: ${data}` );
});
datapod.stderr.on( 'data', data => {
console.log( `stderr: ${data}` );
})
datapod.on( 'close', code => {
console.log( `child process exited with code ${code}` );
})当我这样做的时候,一切都运行得很好
npm启动
我还可以看到python应用程序的日志。当我这么做的时候
npm运行电子:linux
应用程序使用二进制文件成功编译(因为使用二进制文件编译的应用程序的大小恰好等于二进制文件的裸角应用程序+大小)。当我尝试运行这个已编译的应用程序时,它失败了,并显示以下错误。

更新:我尝试了一种不同的方法,仍然没有结果。我已经创建了一个新的文件夹datapod/bin,并将可执行的二进制文件"datapod“复制到这个文件夹中。要将此文件夹复制到打包的应用程序中,请将以下代码行添加到electron-builder.js
"files": [
"**/*",
"!**/*.ts",
"!*.code-workspace",
"!LICENSE.md",
"!package.json",
"!package-lock.json",
"!src/",
"!e2e/",
"!hooks/",
"!angular.json",
"!_config.yml",
"!karma.conf.js",
"!tsconfig.json",
"!tslint.json",
"externals/bin"
],在main.ts文件中编辑我的代码
const appPath = process.env.NODE_ENV === 'production' ? process.resourcesPath : __dirname;
const execPath =path.join(appPath, 'externals/bin/datapod');
console.log(execPath)编译成功,当我尝试运行这个应用程序时,我得到了相同的错误。我使用以下命令将应用程序解压到/tmp/.moun-angular*/resources/app.asar
npx asar extract /tmp/.mount_angulaG6ARST/resources/app.asar extrractedApp文件夹的内容有外部/bin/datapod文件,但无法运行。
发布于 2020-05-18 05:54:20
将此代码片段添加到您的electron builder.json中。
"extraResources": [
{
"from": "src/bin",
"to": "bin",
"filter": "**/*"
}
],此时,文件将被复制到应用程序的根bin文件夹中。下面是我创建的一个函数,用于在开发和生产模式下执行该文件。
const root = process.cwd();
getBinaryPath(binaryName: string) {
const binariesPath = this.isProduction() ? path.join(root, 'resources', 'bin') : path.join(root, 'src', 'bin');
return path.resolve(path.join(binariesPath, binaryName));
}https://stackoverflow.com/questions/58025246
复制相似问题