extrabacon / python-shell

Run Python scripts from Node.js with simple (but efficient) inter-process communication through stdio
2.12k stars 224 forks source link

How to pass dash-dash arguments to Pythong Shell? #274

Closed Jahongir780110 closed 1 year ago

Jahongir780110 commented 2 years ago

I want to run "python detect.py --weights yolov7.pt" command from node.js. My node.js code:

const PythonShell = require("python-shell").PythonShell;
PythonShell.run("../yolov7/detect.py", null, function (err) {
  if (err) throw err;
  console.log("finished");
});

How can i pass --weights yolov7.pt?

I tried to run

PythonShell.run("../yolov7/detect.py --weights yolov7.pt", null, function (err) {
  if (err) throw err;
  console.log("finished");
});

But it didn't work

krsbx commented 2 years ago

From your code, actually you are almost there to make it works. If you see the docs, actually you can pass an options while running/executing your python code with the PythonShell.run functions. To run your python code with an arguments, you can do it this way

PythonShell.run(
    '../yolov7/detect.py',
    {
      args: ['--weights', 'yolov7.pt'],
    },
    function (err) {
      if (err) throw err;
      console.log('finished');
    }
  );
Jahongir780110 commented 2 years ago

Thank you!