我正在尝试使用带有NodeJS的python脚本,它将使用python'hello world'脚本,但是当脚本使用pandas时我无法执行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})
});
});
蟒蛇:
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
始终检查从其他进程运行的命令是否使用与您期望的Python相同的可执行文件。常见的方法是
which python3
要么
where python3
从你的shell,或
import sys
print(sys.executable)
在你的Python脚本中。