我正在尝试从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脚本上使用的库上的不同'import'错误。
File "py_project/fListener.py", line 1, in <module>
import sseclient
通过node.js云函数执行python脚本的正确方法是什么?
谢谢。
最佳答案
这是一种从Cloud Function调用Python脚本而不使用python-shell的方法。这个想法是将Python代码与PyInstaller(“将Python程序冻结(打包)成独立的可执行文件的程序”)打包成一个可自行执行的单元,该单元随后由node.js脚本执行的功能使用。在此Stack Overflow topic中进行了更深入的讨论。