【问题标题】:Error: ModuleNotFoundError: No module named 'email.FeedParser'错误:ModuleNotFoundError:没有名为“email.FeedParser”的模块
【发布时间】:2019-10-31 04:38:47
【问题描述】:

尝试导入以下 Python 库时出现错误:ModuleNotFoundError: No module named 'email.FeedParser':

from googleapiclient import discovery
from httplib2 import Http
from oauth2client import file, client, tools

我正在使用 Python 2.7。这些导入位于从终端调用时可以正常工作的 Google API Python 脚本中。但是,从 nodejs 应用程序调用它们会导致出现此错误。

我已按照以下编号的步骤进行操作: https://cloud.google.com/appengine/docs/standard/python/tools/using-libraries-python-27#vendoring 使用 lib 文件夹添加库

这解决了 googleapiclient 的初始问题,但它似乎不适用于 httplib2 库。

知道我可能缺少什么吗?

这是调用脚本的nodejs代码:

app.post('/newProject', (req, res) => {
  //Get date from form

  var nombre = req.body.nombre;

  var PythonShell = require('python-shell');
  var options = {
    args: [nombre], // pass arguments to the script here
  };

  //you can use error handling to see if there are any errors
  ps.PythonShell.run('./createFolder.py', options, function (err, results) {
    if (err) throw err;
    console.log('results: %j', results);
  });
  //your code

  //send result
  res.send(`Full asda is:${nombre}.`)

});

这是完整的错误:

错误:ModuleNotFoundError:没有名为“email.FeedParser”的模块 在 PythonShell.parseError (/Users/pol/Documents/sf/lego/legoUI/node_modules/python-shell/index.js:246:21) 在 terminateIfNeeded (/Users/pol/Documents/sf/lego/legoUI/node_modules/python-shell/index.js:129:32) 在子进程。 (/Users/pol/Documents/sf/lego/legoUI/node_modules/python-shell/index.js:121:13) 在 ChildProcess.emit (events.js:182:13) 在 Process.ChildProcess._handle.onexit (internal/child_process.js:240:12) ----- Python 回溯 ----- 文件“createFolder.py”,第 4 行,在 导入创建文件夹V01 文件“/Users/pol/Documents/sf/lego/legoUI/createFolderV01.py”,第 3 行,在 从 googleapiclient 导入发现 文件“/Users/pol/Documents/sf/lego/legoUI/lib/googleapiclient/discovery.py”,第 52 行,在 导入 httplib2 文件“/Users/pol/Documents/sf/lego/legoUI/lib/httplib2/init.py”,第 28 行,在 导入 email.FeedParser

编辑:解决了。事实证明,您可以指定哪个 python 解释器 nodejs 将作为选项参数调用。

【问题讨论】:

  • 你做了npm i吗?或者也许做一个npm i python-shell
  • 您好!是的,我做到了。而且我能够很好地执行其他脚本。错误似乎在导入。

标签: node.js python-2.7 google-app-engine google-apps-script google-sheets


【解决方案1】:

解决了。问题是节点试图使用 Python 3 执行脚本,而谷歌库都是使用 python 2.7 完成的。为了强制它使用 Python 2,我添加了

var options = {
        pythonPath: '/usr/bin/python2.7',
        args: [nombre], // pass arguments to the script here
};

执行脚本的选项的 pythonPath。

【讨论】:

    【解决方案2】:

    如果从命令行运行时发生此问题。将 CLOUDSDK_PYTHON 设置为使用 python2 对我有用。

    export CLOUDSDK_PYTHON=python2

    【讨论】:

      猜你喜欢
      • 2019-06-28
      • 2020-07-30
      • 2022-01-13
      • 2020-01-01
      • 2019-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多