我试图从Node.js调用python脚本。它正在执行python脚本,但脚本中的错误为ImportError:no module named google.cloud
我的Node.js有以下代码:
/**
* * Background Cloud Function to be triggered by Cloud Storage.
* *
* * @param {object} event The Cloud Functions event.
* * @param {function} callback The callback function.
* */
exports.hellogcspy1 = function (event, callback) {
var PythonShell = require('python-shell');
var options = {
mode: 'text',
pythonPath: '/usr/bin/python2.7',
pythonOptions: ['-u'],
scriptPath: '.',
args: ['value1', 'value2', 'value3']
};
PythonShell.run('my_script.py', options, function (err, results) {
if (err) throw err;
console.log('results: %j', results);
});
};
python脚本命名为my_script.py。当我从创建python-shell和package.json的目录运行此脚本时,我没有得到任何导入错误。 Package.json有以下代码:
{
"name": "python-shell",
"version": "0.4.0",
"description": "to test python run",
"main": "Node.js",
"scripts": {
"test": "python my_script.py"
},
"keywords": [
"python"
],
"author": "",
"license": "ISC",
"dependencies": {
"python-shell": "^0.4.0"
},
"repository": {},
"devDependencies": {}
}
my_script.py包含google-cloud模块的导入,即
from google.cloud import storage,from google.cloud import bigquery
from google.cloud.bigquery import SchemaField
它在VM上正常运行但在Node.js上运行不正常。任何人都可以帮助我从Node.js执行错误ImportError:no module named google.cloud
的原因吗?