I have an nodejs app which calls python script from a controller. Scripts run fine when I run from terminal directly and works fine as well when called from node app but it only stucks on this specific line model = pickle.load(open("model.pkl", "rb"))
. Any help would be appreciated.
predict.py
import sys
import json
import pickle
import os
def get_size(weight, height, age):
model = pickle.load(open("model.pkl", "rb"))
return model.predict([[height,weight,age,bmi]])[0]
calculated_size = get_size(69,167,26)
print(calculated_size)
sys.stdout.flush()
results.js
const scriptPath = path.dirname(require.main.filename) + '/python-scripts/predict.py';
const pythonProcess = spawn('python', [ scriptPath, 'user_inputs', JSON.stringify(results) ], {cwd: path.dirname(require.main.filename)+'/python-scripts'});
pythonProcess.stdout.on('data', async (data) => {
console.log(data.toString());
})
Fixed by changing python version in spawn:
const pythonProcess = spawn('python3', [ scriptPath, 'user_inputs', JSON.stringify(results) ], {cwd: path.dirname(require.main.filename)+'/python-scripts'});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.