我正在尝试在通过 aws elastic beanstalk 部署的 nodejs 应用程序内的子进程中运行第 3 方 python 库。
这是我调用 spawn 函数的地方:
router.post("/score", async (req, res) => {
let survey = req.body.survey;
let user = req.body.user;
let dataToSend;
const python = spawn('python', ['scoring_script_2.py', JSON.stringify(survey)]);
python.stdout.on('data', function (data) {
console.log('Pipe data from python script ...', data.toString());
dataToSend = data;
});
以下是正在运行的 python 文件中的相关位:
import pandas as pd
import os
import ast
import numpy as np
import json
import sys
os.getcwd()
mapping = pd.read_csv('some_file.csv')
...more code manipulating the pandas dataframe here...
def json2score(survey)
...more code defining the variable to be sent/printed here...
print(json.dumps(scores))
current_score = json2score(sys.argv[1])
通过在自定义 conda 环境中运行服务器,我已经能够在 localhost 的机器上成功运行它,但是当我尝试将它部署到 aws 时,应用程序崩溃了,因为它无法识别 pandas、numpy 和任何其他第 3 方库。
关于如何定制我的 nodejs aws 环境以包含这些 python 库的任何想法?谢谢!