我试图通过NodeJS调用python脚本,它将与python'hello world'脚本一起使用,但是当该脚本使用pandas时,我无法执行该python脚本。
numpy == 1.15.1熊猫== 0.23.4
节点JS
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
从您的壳,或
import sys
print(sys.executable)
在您的Python脚本中。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句