为什么在部署到AppEngine时未安装requirements.txt?

时间:2018-11-16 19:34:36

标签: python-3.x google-app-engine google-cloud-platform pip requirements

我正在尝试将现有项目升级到新的Python 3 AppEngine标准环境。我能够部署我的应用程序代码,但是该应用程序崩溃了,因为它找不到在requirements.txt文件中定义的依赖项。该应用程序的文件结构如下所示:

|____requirements.txt
|____dispatch.yaml
|____dashboard
| |____dashboard.yaml
| |____static
| | |____gen
| | | |____favicon.ico
| | | |____fonts
| | | | |____MaterialIcons-Regular.012cf6a1.woff
| | | |____app.js
| | |____img
| | | |____avatar-06.png
| | | |____avatar-07.png
| | | |____avatar-05.png
| | | |____avatar-04.png
| |____templates
| | |____gen
| | | |____index.html
| |____main.py
| |____.gcloudignore
|____.gcloudignore

requirements.txt文件如下:

Flask==0.12.2
pyjwt==1.6.1
flask-cors==3.0.3
requests==2.19.1
google-auth==1.5.1
pillow==5.3.0
grpcio-tools==1.16.1
google-cloud-storage==1.13.0
google-cloud-firestore==0.30.0
requests-toolbelt==0.8.0
Werkzeug<0.13.0,>=0.12.0
firestore-model>=0.0.2

部署后,当我访问Web站点时,我得到502。GCP控制台错误报告服务指示错误是从main.py中的一行抛出的,该行尝试导入上述依赖项之一:ModuleNotFoundError: No module named 'google'

我尝试将requirements.txt移到仪表板文件夹中并获得相同的结果。

堆栈跟踪:

Traceback (most recent call last):
  File "/env/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
    worker.init_process()
  File "/env/lib/python3.7/site-packages/gunicorn/workers/gthread.py", line 104, in init_process
    super(ThreadWorker, self).init_process()
  File "/env/lib/python3.7/site-packages/gunicorn/workers/base.py", line 129, in init_process
    self.load_wsgi()
  File "/env/lib/python3.7/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/env/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/env/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
    return self.load_wsgiapp()
  File "/env/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/env/lib/python3.7/site-packages/gunicorn/util.py", line 350, in import_app
    __import__(module)
  File "/srv/main.py", line 12, in <module>
    from google.cloud import storage
ModuleNotFoundError: No module named 'google'

1 个答案:

答案 0 :(得分:1)

有些事情可能会出错。确保:

  • 您的requirements.txt文件与您的main.py文件位于同一目录
  • 您的.gcloudignore不会忽略您的requirements.txt文件
  • 您要在与requirements.txtmain.py相同的目录中部署函数