python - AttributeError:模块“x”没有属性“y”
问题描述
我正在尝试将 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'
解决方案
创建函数时,Google Cloud Functions 似乎没有下载子模块。
下载源代码导致子模块文件夹为空,这就解释了为什么会发生 arrtibute 错误。
推荐阅读
- c# - iOS Xamarin 上的实体框架连接在屏幕关闭时关闭
- github - 如何将下载的 Github Repo 推回来?
- c++ - 具有相同名称的类的构造函数继承
- android - 自定义控件:滑开时按钮释放事件不会触发
- macos - 如何在 mac os catalina 上使用 npm start?
- google-cloud-platform - 云容器集群创建`compute.networks.get`权限错误
- javascript - 为 Count Ifs 创建脚本(2 个条件)
- python - 在 MySQL 数据库中保存 pandas 数据帧的最快方法是什么
- maven - 为什么我打包的jar中没有kotlin-reflect库?
- c# - 异步写入文件时如何避免 System.IO.FileLoadException