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

PythonShell.runString is not a constructor #308

Closed chrismatthieu closed 4 months ago

chrismatthieu commented 4 months ago

I get the following error when running python strings: PythonShell.runString is not a constructor

Ubuntu NodeJS 22.3.0

        import {PythonShell} from 'python-shell';

    let pyShell = new PythonShell.runString(pythonScriptString, null);
    pyShell.on('error', function (err) {
        console.log('err', err);
    })
    pyShell.on('message', function(message) {
        console.log('message', message);
    })
    pyShell.on('end', function(err, code, signal) {
        if(err) throw err;
        console.log('exit code', code);
        console.log('exit signal', signal);
        console.log('finished');
    })
daizhengqing commented 4 months ago

not new PythonShell.runString,just PythonShell.runString

Almenon commented 4 months ago

see @daizhengqing's answer. 谢谢!

For more context, runString is not a constructor. but you are calling it like it is a constructor.

chrismatthieu commented 4 months ago

When I remove new from the initial line, I get a subsequent error saying:

error TypeError: pyShell.on is not a function