Node.js Pythonshell找不到脚本

时间:2020-08-07 06:07:32

标签: python node.js

我的nodejs api需要使用python脚本。我尝试了一些技巧。

Nodejs

var express = require('express');
var router = express.Router();
let {PythonShell} = require('python-shell');

router.get('/pyt', (req, res, next)=> {

    console.log("router get");
# also I tryed with inside the routes folder with PythonShell.run('sample.py', 
    PythonShell.run('../pyt/sample.py', {
      args: ['hello']
      }, function (err, results) {   
          console.log("pshell run");
        if(results)
        { 
           console.log(results);
         }
        if(err)
            { 
             console.log(err);
            }
        });
      });

Python

import sys
import os

print("first")

if __name__ == "__main__":
    print("in python script")
    a = sys.argv[1]
    aa=open('sample.txt',"w+")
    aa.close()
    if not os.path.exists(a):
            os.makedirs(a)
    print("last")

当我呼叫http:// localhost:3000 / pyt时,它给出了此错误。 Python error

谢谢

0 个答案:

没有答案