Nodejs Pythonshell не может найти скрипт - PullRequest
0 голосов
/ 07 августа 2020

Мой 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 ошибка

Спасибо

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...