Я пытаюсь вызвать использование скрипта Python с NodeJS, и он будет работать со скриптом Python 'Hello World', но я не могу заставить скрипт Python выполняться, когда в скрипте используются панды.
numpy == 1.15.1 pandas == 0.23.4
nodeJS
router.get('/', (req, res) => {
const filePath = 'python/testing2.py'
const spawn = require("child_process").spawn;
const pythonProcess = spawn('python3',[filePath, '-l']);
util.log('readingin')
pythonProcess.stdout.on('data', (data) => {
const textChunk = data.toString('utf8');// buffer to string
util.log(textChunk);
res.json({'working': true, 'data': textChunk})
});
});
python:
import sys
from pandas import read_csv
from pandas import datetime
def parser(x):
return datetime.strptime('190'+x, '%Y-%m')
print("Output from Python")
series = read_csv('shampoo-sales.csv', header=0, parse_dates=[0], index_col=0, squeeze=True, date_parser=parser)
print (series)
sys.stdout.flush()
если я сам запускаю скрипт python:
$ python3 testing2.py
Output from Python
Month
1901-01-01 266.0
1901-02-01 145.9
1901-03-01 183.1
1901-04-01 119.3...
$ pip3 freeze
matplotlib==2.2.3
numpy==1.15.1
pandas==0.23.4