从Node.js运行Python脚本——获取导入错误:没有名为google.cloud的模块
我正在尝试从Node.js调用python脚本。它正在执行python脚本,但在脚本中给出错误,如从Node.js运行Python脚本——获取导入错误:没有名为google.cloud的模块,python,node.js,google-cloud-platform,google-cloud-functions,Python,Node.js,Google Cloud Platform,Google Cloud Functions,我正在尝试从Node.js调用python脚本。它正在执行python脚本,但在脚本中给出错误,如ImportError:no module name google.cloud my Node.js包含以下代码: /** * * Background Cloud Function to be triggered by Cloud Storage. * * * * @param {object} event The Cloud Functions event. * *
ImportError:no module name google.cloud
my 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);
});
};
{
"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": {}
}
python脚本名为my_script.py。当我从创建pythonshell和package.json的目录运行这个脚本时,我没有得到任何导入错误。
Package.json包含以下代码:
/**
* * 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);
});
};
{
"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包含谷歌云模块的导入,即
from google.cloud import storage,from google.cloud import bigquery
from google.cloud.bigquery import SchemaField
它在VM上运行正常,但在Node.js上运行不正常。有人能告诉我为什么从Node.js执行时出现错误
ImportError:no module name google.cloud
?尝试版本google cloud==0.27.0,之前的版本有一些不一致的依赖项您建议安装此版本的google cloud吗?我运行$pip show google cloud并得到以下结果:pip show google cloud名称:google cloud版本:0.27.0摘要:google cloud的API客户端库主页:作者:google cloud平台作者电子邮件:googleapis-publisher@google.com许可证:Apache2.0位置:/usr/lib64/python2.7/site-packages要求:谷歌云翻译,谷歌云资源管理器,谷歌云dns,谷歌云bigquery。。。。。。。看起来它只是最新版本。当您从创建python shell和package.json的目录运行脚本时,你使用python 2.7还是3.x?它是python2.7,因为当我运行脚本时,它会进入路径/usr/lib/python2.7/site packages/google/cloud/storage…当你打开/usr/bin/python2.7
的实时解释器并尝试导入google.cloud
时会发生什么?