Google App Engine-Python 3-ModuleNotFoundError:没有名为“ pytz”的模块

时间:2018-09-21 14:46:03

标签: python google-app-engine python-import pytz

我正在尝试在标准Python37环境中部署到Google App Engine。我有一个以前的版本,没有使用pytz或请求,但是确实使用了外部python库。

添加这些依赖项并进行部署然后查看网站后,出现500错误。查看日志显示:

  

ModuleNotFoundError:没有名为“ pytz”的模块
  ModuleNotFoundError:没有名为“ requests”的模块

docs说Python应用程序的依赖项是在标准requirements.txt文件中声明的。我已经做到了。

requirements.txt的内容

  

click == 6.7
     烧瓶== 1.0.2
     geojson == 2.4.0
     itsdangerous == 0.24
     Jinja2 == 2.10
     MarkupSafe == 1.0
     pkg-resources == 0.0.0
     pymongo == 3.7.1
     pytz == 2018.5
     Werkzeug == 0.14.1

我的app.yaml

runtime: python37

handlers:
- url: /static
  static_dir: static

- url: /.*
  script: auto

main.py的开始

import json
import time
import pytz
import requests   

堆栈跟踪中的错误:

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 4, in <module> 
    import pytz 
ModuleNotFoundError: No module named 'pytz'`enter code here`

我已经在GAE上本地安装并测试了这些模块,并验证了它们是否可以工作。错误仅在部署时出现。任何有关如何解决这些错误并成功部署的建议,将不胜感激。

  

编辑:

     

我已经更新了我的requirements.txt以添加请求并删除   pkg-resources开始生成时出现错误。内容   requirements.txt

     
    

click == 6.7
       烧瓶== 1.0.2
       geojson == 2.4.0
       itsdangerous == 0.24
       Jinja2 == 2.10
       MarkupSafe == 1.0
       pymongo == 3.7.1
       pytz == 2018.5
       个请求== 2.18.4
       Werkzeug == 0.14.1

  

1 个答案:

答案 0 :(得分:0)

我能够部署以下应用程序:

app.yaml中:

runtime: python37

handlers:
- url: /static
  static_dir: static

- url: /.*
  script: auto

requirements.txt中:

click==6.7
Flask==1.0.2
geojson==2.4.0
itsdangerous==0.24
Jinja2==2.10
MarkupSafe==1.0
pymongo==3.7.1
pytz==2018.5
requests==2.18.4
Werkzeug==0.14.1

main.py中:

from flask import Flask

import pytz

app = Flask(__name__)


@app.route('/')
def hello():
    """Return a friendly HTTP greeting."""
    return pytz.VERSION

这将成功返回pytz的版本。

您确定新的需求文件包含pytz并且正在部署吗?您可以通过在Google Cloud Console中导航到以下内容进行检查:

资源> App Engine > 服务,然后在您的服务所在的行中,诊断> 工具> 来源。从那里可以找到requirements.txt文件,并验证它是否包含pytz==2018.5