【问题标题】:Invoking python in AWS lambda import error在 AWS lambda 导入错误中调用 python
【发布时间】: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


【解决方案1】:

我在 Amazon Linux 上做所有事情,就像在我的 ubuntu 机器上一样。它的工作。解释here

为了在 AWS Lambda 中工作,需要为 Amazon Linux x86_64" 编译扩展模块

【讨论】:

    猜你喜欢
    • 2018-06-20
    • 2016-05-22
    • 1970-01-01
    • 1970-01-01
    • 2019-03-13
    • 1970-01-01
    • 2021-03-19
    • 2019-11-01
    • 2021-05-04
    相关资源
    最近更新 更多