SyntaxError when firing python scirpt in nodejs

I'm using python-shell package for nodejs to fire a python script, which return SyntaxError: invalid syntax.

Nodejs code

const options = {
    mode: 'text',
    pythonPath: '/usr/bin/python3',
    scriptPath: __dirname + '/script',
};
var pyshell = new PythonShell('test.py', options);

pyshell.send('hello');

pyshell.on('message', function (message) {
  // received a message sent from the Python script (a simple "print" statement)
  console.log(message);
});

// end the input stream and allow the process to exit
pyshell.end(function (err,code,signal) {
  if (err) throw err;
  console.log('The exit code was: ' + code);
  console.log('The exit signal was: ' + signal);
  console.log('finished');
});

Python script

print(f'test')

Error

PythonShellError:   File "/app/src/back/script/test.py", line 1
print(f'meas')
            ^
SyntaxError: invalid syntax

If i run the script, with the command : python3 test.py , i'm getting the word 'test' printed as excepeted, but not with the use of python-shell as i want to. My python version is 3.8.10



Read more here: https://stackoverflow.com/questions/68486630/syntaxerror-when-firing-python-scirpt-in-nodejs

Content Attribution

This content was originally published by Tollaris at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: