electron打包找不到python
在 mac 升级后,出现过 git 找不到的问题。后来又在 electron 打包的时候出现了 python 找不到的问题。
# 问题
在 electron 打包 mac 版本,出现报错。
⨯ Exit code: 1. Command failed: which python
failedTask=build stackTrace=Error: Exit code: 1. Command failed: which python
1
2
2
根据这篇博文 (opens new window),尝试从源码入手,找到node_modules/dmg-builder/out/dmg.js
,找到如下代码:
const executePython = async (execName) => {
let pythonPath = process.env.PYTHON_PATH
if (!pythonPath) {
pythonPath = (await builder_util_1.exec('which', [execName])).trim()
}
await builder_util_1.exec(pythonPath, [path.join(dmgUtil_1.getDmgVendorPath(), 'dmgbuild/core.py')], {
cwd: dmgUtil_1.getDmgVendorPath(),
env,
})
}
try {
await executePython('python3')
} catch (error) {
await executePython('python')
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
发现它其实是兼容 python2 和 python3 的,但是还是报错了,于是加上日志。
try {
console.log('python3')
await executePython('python3')
} catch (error) {
console.log('python', error)
await executePython('python')
}
1
2
3
4
5
6
7
2
3
4
5
6
7
重新执行 build,截到报错。
python Error: Exit code: 1. Command failed: /usr/bin/python3 /Users/macbookpro/Documents/app/test/demos/electron-demos/mini-cup/node_modules/dmg-builder/vendor/dmgbuild/core.py
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
1
2
2
提示找不到xcrun
,在 stackoverflow 找到类似的问题(才发现就是先前找过的)。安装最新的 Command_Line_Tools_for_Xcode 后重启电脑,就可以正常打包了。
上次更新: 2022/11/03, 18:40:54