从node.js调用python脚本时出错

时间:2018-03-11 17:09:52

标签: python node.js python-3.x python-2.7

我收到此错误。所以基本上python脚本是从nodejs函数成功调用的。但是,由于我使用“python-shell”进行调用,因此它使用默认版本Python2.7进行调用。我的python脚本中有一个函数list.copy(),这是Python3.x中的一个补充。如何更改“python-shell”中的python版本

Error: AttributeError: 'list' object has no attribute 'copy'
    at PythonShell.parseError (/Users/neelkapadia/Desktop/NCSU/SE/WolfPlanner/node_modules/python-shell/index.js:184:17)
    at terminateIfNeeded (/Users/neelkapadia/Desktop/NCSU/SE/WolfPlanner/node_modules/python-shell/index.js:98:28)
    at ChildProcess.<anonymous> (/Users/neelkapadia/Desktop/NCSU/SE/WolfPlanner/node_modules/python-shell/index.js:89:9)
    at ChildProcess.emit (events.js:180:13)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:209:12)
    ----- Python Traceback -----
    File "scheduler/core_scheduler.py", line 194, in <module>
      schedule = generate_schedule(unityId, day_date, student_record, buffer_time)
    File "scheduler/core_scheduler.py", line 87, in generate_schedule
      new_tasks = sorted_tasks.copy()
  traceback: 'Traceback (most recent call last):\n  File "scheduler/core_scheduler.py", line 194, in <module>\n    schedule = generate_schedule(unityId, day_date, student_record, buffer_time)\n  File "scheduler/core_scheduler.py", line 87, in generate_schedule\n    new_tasks = sorted_tasks.copy()\nAttributeError: \'list\' object has no attribute \'copy\'\n',
  executable: 'python',
  options: null,
  script: 'scheduler/core_scheduler.py'

P.S:以下是调用python脚本的节点js代码。

module.exports = {
    call_python: function(unityId, buffer_time, day_date, callback){

    var options = {
        args: [unityId, day_date, buffer_time]
    };

    var shell = require('python-shell')

    shell.run('scheduler/core_scheduler.py', options, function (err, results) {
        if (err) console.log(err);
        console.log('results: %j', results);
        });

0 个答案:

没有答案