如何解决在 anaconda 环境中从 nodejs
我正在使用以下参数调用特定文件 main.py:
main.py --train --num_epoch 100 --id 93
在“gangan”的 conda 环境中
以下是我的代码:
const express = require('express')
const {spawn} = require('child_process');
const app = express()
const port = 3000
app.get('/',(req,res) => {
var dataToSend;
// spawn new child process to call the python script
const environmentName = 'gangan';
const pythonScript = './synthetic-time-series-smart-grid-master/main.py';
const command = `conda run -n ${environmentName} python ${pythonScript}`;
const python = spawn(command,{ shell: true });
// collect data from script
python.stdout.on('data',function (data) {
console.log('Pipe data from python script ...');
dataToSend = data.toString();
});
// in close event we are sure that stream from child process is closed
python.on('close',(code) => {
console.log(`child process close all stdio with code ${code}`);
// send data to browser
res.send(dataToSend)
});
})
app.listen(port,() => console.log(`Example app listening on port ${port}!`))
我运行时得到的唯一输出是 enter image description here 在 HTML 中。
这是程序正常执行的方式 enter image description here
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com(将#修改为@)