python - 从index.js云函数运行python脚本

标签 python node.js google-cloud-functions

我正在尝试从node.js-云函数索引文件运行python 脚本。 为了访问 python 脚本,我还使用“python-shell”... 问题是每次我运行部署 index.js 文件的功能时, 它打印此错误:

Error: python: can't open file '../Python36/fListener.py': [Errno 2] 
                     No such file or directory

at PythonShell.parseError (/user_code/node_modules/python-
 shell/index.js:190:17)
at terminateIfNeeded (/user_code/node_modules/python-shell/index.js:98:28)
at Socket.<anonymous> (/user_code/node_modules/python-shell/index.js:78:9)
at emitNone (events.js:91:20)
at Socket.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickDomainCallback (internal/process/next_tick.js:128:9)

另外,我尝试在node.js“functions”文件夹中创建python项目,但它向我指出了我试图在python脚本上使用的库上的不同“导入”错误。如下所示:

 File "py_project/fListener.py", line 1, in <module>
      import sseclient

通过node.js云函数执行python脚本的正确方法是什么?

谢谢。

最佳答案

这里有一种从云函数调用 Python 脚本的稍微不同的方法,无需使用 python-shell。这个想法是将Python代码打包为PyInstaller (“将 Python 程序卡住(打包)为独立可执行文件的程序”)到一个自可执行单元,稍后由 Node.js 脚本执行的函数使用。在此 Stack Overflow topic 中对此进行了更深入的讨论。 .

关于python - 从index.js云函数运行python脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48136501/

相关文章:

Python 相当于 atoi/atof

python - 如何用线性回归绘制散点图?

mongodb - 使用 mapReduce 选择一行中的所有字段

javascript - 最小化 Node.js 同步等待 http 请求

typescript - Firebase 模拟器缺少 tsconfig.json?

javascript - Firebase 函数环境变量无法读取未定义的属性

google-cloud-functions - 部署功能失败: "artifactregistry.repositories.downloadArtifacts" denied but service account has policy granted

Python - 按照命令写入文件

python - 通过 Python 和 Google SMTP 服务器发送电子邮件

javascript - Bower 安装 > 类型错误 : msecs must be a number