我想在服务器(Google Compute Engine)中运行python脚本。所以我使用python-shell创建了一个Cloud Function代码。但是出现了这个错误。
错误:python:无法打开文件 ' /home/dmproject0608/test2/FaceDetect_.py':[Errno 2]没有这样的文件或 目录
这是我的云功能:
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);
});
});
});