I have been trying to follow the documentation for the npm pythonshell here. I\'m just trying to get a simple example to function correctly with no success, not many examples on
So I made the mistake of not checking my python path on a new system install, however using an absolute path is also nessasary for the script to function. Here is a working example for anyone trying to run python scripts using nodejs python-shell npm. Thanks to Bryan for helping me with javascript error.
var PythonShell = require('python-shell');
var options = {
mode: 'text',
pythonPath: '/usr/bin/python',
pythonOptions: ['-u'],
// make sure you use an absolute path for scriptPath
scriptPath: '/home/username/Test_Project/Python_Script_dir',
args: ['value1', 'value2', 'value3']
};
PythonShell.run('test.py', options, function (err, results) {
if (err) throw err;
// results is an array consisting of messages collected during execution
console.log('results: %j', results);
});