【发布时间】:2016-02-02 01:03:50
【问题描述】:
我正在尝试在 AWS lambda 函数中调用 python 脚本。我为 python 创建了一个虚拟环境,并安装了 pandas、pymongo 等所需的模块。这是我的 invokepython.js:
var exec = require('child_process').exec;
exports.handler = function(event, context) {
console.log('Received event:', JSON.stringify(event, null, 2));
exec("env/bin/python kinesisconsumer.py '"+ JSON.stringify(event) +"'", function(error, stdout) {
console.log('Python returned: ' + stdout + '.');
context.done(error, stdout);
});
};
我已经安装了virtualenv 并使用它创建了一个环境。使用env/bin/pip install pandas 我已经安装了熊猫。我已将 env 文件夹和我的脚本压缩在一起,并将其部署到 AWS lambda,但出现错误。
{
"errorMessage": "Command failed: Traceback (most recent call last):\n File \"kinesisconsumer.py\", line 4, in <module>\n import pandas as pd\n File \"/var/task/env/local/lib/python2.7/site-packages/pandas/__init__.py\", line 13, in <module>\n \"extensions first.\".format(module))\nImportError: C extension: libcrypto.so.1.0.0: cannot open shared object file: No such file or directory not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace' to build the C extensions first.\n",
"errorType": "Error",
"stackTrace": [
" File \"kinesisconsumer.py\", line 4, in <module>",
" import pandas as pd",
" File \"/var/task/env/local/lib/python2.7/site-packages/pandas/__init__.py\", line 13, in <module>",
" \"extensions first.\".format(module))",
"ImportError: C extension: libcrypto.so.1.0.0: cannot open shared object file: No such file or directory not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace' to build the C extensions first.",
"",
"ChildProcess.exithandler (child_process.js:658:15)",
"ChildProcess.emit (events.js:98:17)",
"maybeClose (child_process.js:766:16)",
"Process.ChildProcess._handle.onexit (child_process.js:833:5)"
]
我需要在 AWS lambda 上使用 pandas。我应该如何解决这个问题。任何帮助表示赞赏!!!
【问题讨论】:
-
使用轮子,已经遵守。
-
@e-nouri 我没听懂。如何使用轮子
-
wheels 是已经编译好的 python 包/库,pip 只会在你的环境中解包它们。
-
为什么不直接用node.js呢?!
-
@e-nouri 我需要做一些数据帧操作,并且已经有很多用 python 编写的脚本。轮子与 pip 安装有何不同。我的意思是 pandas 安装在我的 virtualenv 中。
标签: python aws-lambda