gpt4 book ai didi

python - 部署云函数时index.js出错

转载 作者:太空宇宙 更新时间:2023-11-04 02:00:28 25 4
gpt4 key购买 nike

我正在尝试使用 Cloud Function 事件触发器执行 python 脚本。我的index.js有以下代码:

var PythonShell = require('python-shell');

PythonShell.run('my_script.py', function (err) {
if (err) throw err;
console.log('finished');
});

exports.processFile = function(event, callback) {
console.log('Processing file: ' + event.data.name);
callback();
};

module.exports = PythonShell;

package.json 有以下代码:

{ 
"name": "python-shell",
"version": "0.4.0",
"description": "Run Python scripts from Node.js with simple (but efficient) inter-process communication through stdio",
"keywords": [
"python"
],
"scripts": {
"test": "my_script.py"
},
"dependencies" : {}
}

但是该函数尚未创建。它显示以下错误:错误:

Deployment failure:
Function load error: Code in file index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'python-shell'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/user_code/index.js:7:19)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)

请问如何解决?

最佳答案

请先尝试此命令

npm install python-shell

关于python - 部署云函数时index.js出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46197564/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com