[英]Run Python script in a file from Cloud Function
I want to run python script in server (Google Compute Engine).我想在服务器(谷歌计算引擎)中运行 python 脚本。 So I made a Cloud Function code using python-shell.所以我使用 python-shell 制作了一个 Cloud Function 代码。 However this error appeared.但是出现了这个错误。
Error: python: can't open file '/home/dmproject0608/test2/FaceDetect_.py': [Errno 2] No such file or directory错误:python:无法打开文件“/home/dmproject0608/test2/FaceDetect_.py”:[Errno 2] 没有这样的文件或目录
And this is my Cloud Function:这是我的云 Function:
const functions = require('firebase-functions');
const mkdir=require('mkdirp-promise');
const gcs=require('@google-cloud/storage')();
const spawn=require('child-process-promise').spawn;
const path=require('path');
const os=require('os');
const fs=require('fs');
var pythonShell=require('python-shell');
exports.Test = functions.storage.object().onFinalize((object) => {
const filePath = object.name;
const fileName = path.basename(filePath, path.extname(filePath));
const fileDir = path.dirname(filePath);
const fileBucket=object.bucket;
const tempLocalFile = path.join(os.tmpdir(), filePath);
const tempLocalDir = path.dirname(tempLocalFile);
const bucket=gcs.bucket(fileBucket);
if (object.resourceState === 'not_exists') {
console.log('This is a deletion event.');
return;
}
return mkdir(tempLocalDir).then(()=>{
return bucket.file(filePath).download({destination : tempLocalFile});
}).then(()=>{
console.log('Download is complete %j',tempLocalFile);
var options={
mode:'text',
pythonPath:'',
pythonOptions: ['-u'],
scriptPath:'/home/dmproject0608/test2',
args:[ tempLocalFile]
};
pythonShell.run('FaceDetect_.py',options,function(err,results){
if(err) throw err;
console.log('result: %j',results);
});
});
});
May be a bit late for this response, try absolute paths when using Python-shell.此响应可能有点晚,请在使用 Python-shell 时尝试绝对路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.