Python 3.x 导入错误:无法导入名称';firestore&x27;

Python 3.x 导入错误:无法导入名称';firestore&x27;,python-3.x,google-cloud-firestore,streaming,google-cloud-dataflow,Python 3.x,Google Cloud Firestore,Streaming,Google Cloud Dataflow,我正在做一个数据流应用程序,它可以在firestore中编写,当我在DirectRunner上运行时,它可以工作,但当我在DataflowRunner上运行时,它不工作。错误是什么?我的requirements.txt是: apache-beam[gcp,test]==2.19.0 google-cloud-pubsub google-cloud-firestore==0.29.0 抛出exeption的代码行是: from google.cloud import firestore db =

我正在做一个数据流应用程序,它可以在firestore中编写,当我在DirectRunner上运行时,它可以工作,但当我在DataflowRunner上运行时,它不工作。错误是什么?我的
requirements.txt
是:

apache-beam[gcp,test]==2.19.0
google-cloud-pubsub
google-cloud-firestore==0.29.0
抛出exeption的代码行是:

from google.cloud import firestore
db = firestore.Client(project=project)

这在Dataflow常见问题解答中有记录,处理这一问题的方法很少

  • 在函数定义中使用
    import
    语句
  • 在管道选项中将
    save_main_session
    设置为True
  • 使用requirements.txt和setup.py文件定义依赖项并适当组织文件夹结构

  • 更多细节可以在这里找到-

    我发现了一个类似的线程,答案在这里吗?是的,但是没有。它不起作用。我看到,如果导入放在使用firestore的函数中,它就会启动,相反,如果我把它放在模块的顶部,它就不会启动。这对你有帮助吗?你能分享你导入的代码吗?是的,我已经更新了我的帖子