python-shell icon indicating copy to clipboard operation
python-shell copied to clipboard

Running python script with switch -m error

Open smadurange opened this issue 6 years ago • 1 comments

Hi guys,

I'm trying to run a script with the switch -m. My code looks like:

app.get('/test-scraper', (req, res, next) => {
  const { arg0, arg1 } = req.query;
  const options = {
    mode: 'text',
    pythonPath: 'path/bin/python',
    pythonOptions: ['-m'],
    scriptPath: 'path/to/folder',
    args: [arg0, arg1]
  };
  PythonShell.run('script.py', options, (err, results) => {
      if (err) next(err);
      res.json(results);
  })

However, I'm getting the error:

Error: Error while finding module specification for 'script.py' (ModuleNotFoundError: No module named 'script.py')

    at PythonShell.parseError (/node_modules/python-shell/index.js:191:17)
    at terminateIfNeeded (/node_modules/python-shell/index.js:98:28)
    at ChildProcess.<anonymous> (/node_modules/python-shell/index.js:89:9)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)

I believe this is happening because python-shell is trying to run the script like python -m script.py. Is it possible to configure python-shell to run the script like python -m script? Any other alternative to run the script as a module with the switch -m?

smadurange avatar Apr 20 '18 07:04 smadurange

have you tried doing PythonShell.run('script' ... ?

Almenon avatar Jun 25 '18 03:06 Almenon

No response, closing

Almenon avatar Sep 30 '22 03:09 Almenon

Duplicate of https://github.com/extrabacon/python-shell/issues/7

I personally found https://github.com/extrabacon/python-shell/issues/7#issuecomment-448661769 to work the best, in case anybody is still having this problem.

aloisklink avatar Oct 10 '22 14:10 aloisklink