[英]python-shell with electron-builder work fine in my computer but not working in other computer
這是我的 electron.js 中的 PythonSHELL 腳本:
const {PythonShell} = require('python-shell');
const path = require('path');
const options = {
mode: 'text',
pythonPath: 'C:/Users/abdou/AppData/Local/Programs/Python/Python38/python.exe',
scriptPath: isDev ? `${path.join(__dirname, "db")}`: `${path.join(__dirname, "../../build/db")}`,
};
mainWindow.webContents.on('did-finish-load', ()=>{
PythonShell.run('p.py', options, function (err, results) {
if (err) throw err;
// results is an array consisting of messages collected during execution
mainWindow.webContents.send('data', results[0]);
})
});
這是我的 package.json 腳本標簽:
"react-start": "react-scripts start",
"react-build": "react-scripts build",
"react-test": "react-scripts test --env=jsdom",
"react-eject": "react-scripts eject",
"electron-build": "electron-builder",
"release": "yarn react-build && electron-builder --publish=always",
"build": "yarn react-build && yarn electron-build",
"start": "concurrently \"cross-env BROWSER=none yarn react-start\" \"wait-on http://localhost:3000 && electron .\""
這是構建標簽:
"build": {
"appId": "com.gs_client_descktop",
"asar": false,
"extraResources": [
"**/db/**/*"
]}
消息錯誤是:
Uncaught Exeption:
spawn C:/Users/abdou/AppData/Local/Programs/Python/Python38/python.exe ENONENT
at Process.ChildProcess._handle.onexit(intrnal/child_process.js:264:19)
at onErrorNT (internal/child_process.js:456:16)
at processTicksAndRejections(internal/process/task_queues.js:77:11)
謝謝。
答案很明確。 您已將 pythonPath 鏈接到計算機上的解釋器。 您在此處提供的路徑(在本例中為 --> pythonPath: 'C:/Users/abdou/AppData/Local/Programs/Python/Python38/python.exe'
)僅存在於您的計算機上。 所以它不應該工作。
作為解決方案,您可以在項目中使用 python 虛擬環境。 然后將虛擬環境中的解釋器鏈接到 Python 路徑。 設置到虛擬環境的路徑很可能如下所示:
pythonPath: path.join(__dirname, '/../python/venv/Scripts/python.exe');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.