如何用js节点运行python程序

2024-09-26 18:21:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我有快车节点.js应用程序,但我想用以下命令运行机器学习python codw。你知道吗

我已经找到了一些运行python机器学习的在线解决方案代码。用此堆栈溢出链接 How to call a Python function from Node.js

但是使用这个解决方案,我只运行一个python代码。你知道吗

var spawn = require("child_process").spawn;
      var process = spawn('python', ["./my_script.py"]);
      process.stdout.on('data', function (data) {
        res.send(data.toString());
      })

用这段代码我只运行一个代码python hello.py,但我想用以下命令运行一个代码python test.py --model dataset/test.model --image s.jpg


Tags: 代码pytest命令机器datamodel节点
1条回答
网友
1楼 · 发布于 2024-09-26 18:21:06

你可以使用python-shell

import {PythonShell} from 'python-shell';

const options = {
            args: [
                ' image',
                's.jpg'
            ]
        };

PythonShell.run('script.py', options, (err, results) => {
  // your code 
});

如果要使用生成可以执行以下操作:

const args = ['script.py', ' image', 's.jpg'];
const process = spawn('python', args);

相关问题 更多 >

    热门问题