python-shell
python-shell copied to clipboard
Running python script with switch -m error
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?
have you tried doing PythonShell.run('script' ... ?
No response, closing
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.