Using PythonShell module in Nodejs

后端 未结 1 466
长情又很酷
长情又很酷 2021-02-10 16:29

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

相关标签:
1条回答
  • 2021-02-10 16:50

    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);
        });
    
    0 讨论(0)
提交回复
热议问题