【问题标题】:AttributeError: module 'x' has no attribute 'y'AttributeError:模块“x”没有属性“y”
【发布时间】:2021-04-13 19:33:26
【问题描述】:

我正在尝试将 python 函数移至 Google Cloud Functions,但我似乎遇到了别名问题。

我有一个模块,它的 init 中有以下内容;

import tweetBot.generator, tweetBot.poster

# Add aliases when this module is imported
tweetBot.ebooksGen = tweetBot.generator.ebooksGen
tweetBot.genreGen = tweetBot.generator.genreGen
tweetBot.variantGen = tweetBot.generator.variantGen

tweetBot.postTweet = tweetBot.poster.postTweet

然后使用简单的import tweetBot 导入。

在我的本地机器上运行它,它运行良好,并且该功能绝对没有问题。输出全部正确,一切正常。

但是,当使用 Google Cloud Functions 运行此程序时,我收到以下错误;

AttributeError: module 'tweetBot' has no attribute 'genreGen'

这对我来说绝对没有意义,因为它是在导入中绝对定义的。此外,我知道这是可行的,因为它在我的本地机器上从完全相同的存储库中运行得非常好。

https://github.com/Jademalo/JadeBots/tree/gcp-functions

忽略糟糕的代码,至少它可以工作。我只是不明白为什么我在 Google Cloud 上运行它时会出现属性错误,而它在本地绝对没问题。

谢谢


编辑:用原件替换别名调用后(例如tweetBot.generator.genreGen,我仍然遇到同样的问题;

  File "/workspace/JadeBots.py", line 18, in postGenreDefining
    tweetText, altGenreGameDebug, altGenreExtraDebug, gameText, genreText, altPostDebug = tweetBot.generator.genreGen(gameFile, genreFile, genreExtraFile, altPostFreq, altGenreGameFreq, altGenreExtraFreq)
AttributeError: module 'tweetBot' has no attribute 'generator' 

【问题讨论】:

    标签: python google-cloud-platform


    【解决方案1】:

    Google Cloud Functions 在创建函数时似乎没有下载子模块。

    下载源代码导致子模块文件夹为空,这解释了为什么会发生 arrtibute 错误。

    【讨论】:

      猜你喜欢
      • 2018-05-28
      • 1970-01-01
      • 2018-04-14
      • 2019-02-18
      • 1970-01-01
      • 2020-01-01
      • 2022-06-16
      • 2019-07-20
      相关资源
      最近更新 更多