[英]Google App Engine - Python 3 - ModuleNotFoundError: No module named 'pytz'
I'm trying to deploy to Google App Engine in the standard Python37 Environment.我正在尝试在标准 Python37 环境中部署到 Google App Engine。 I had a previous version working that didn't use pytz or requests however did use external python libraries.
我有一个以前的版本没有使用 pytz 或 requests 但确实使用了外部 python 库。
After adding these dependencies and deploying then viewing the website I get a 500 error.添加这些依赖项并部署然后查看网站后,我收到 500 错误。 Looking at the logs it says:
查看日志它说:
ModuleNotFoundError: No module named 'pytz'
ModuleNotFoundError: 没有名为“pytz”的模块
ModuleNotFoundError: No module named 'requests'ModuleNotFoundError: 没有名为“请求”的模块
The docs say that the dependencies for Python applications are declared in a standard requirements.txt file. 文档说 Python 应用程序的依赖项在标准的 requirements.txt 文件中声明。 Which I have done.
我所做的。
Contents of requirements.txt requirements.txt 的内容
click==6.7
点击==6.7
Flask==1.0.2烧瓶==1.0.2
geojson==2.4.0geojson==2.4.0
itsdangerous==0.24它的危险==0.24
Jinja2==2.10Jinja2==2.10
MarkupSafe==1.0标记安全==1.0
pkg-resources==0.0.0pkg-resources==0.0.0
pymongo==3.7.1pymongo==3.7.1
pytz==2018.5pytz==2018.5
Werkzeug==0.14.1Werkzeug==0.14.1
My app.yaml我的应用程序.yaml
runtime: python37
handlers:
- url: /static
static_dir: static
- url: /.*
script: auto
Start of main.py main.py 的开始
import json
import time
import pytz
import requests
The error from the Stack trace:堆栈跟踪中的错误:
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`
I have installed and tested these modules locally on GAE and verified they work.我已经在 GAE 本地安装并测试了这些模块,并验证了它们的工作原理。 The errors only come when deploying.
错误仅在部署时出现。 Any suggestions on how to fix these errors and deploy successfully would be greatly appreciated.
任何关于如何修复这些错误并成功部署的建议将不胜感激。
edit:
编辑:
I've updated my requirements.txt to add requests and to remove pkg-resources as that started to give errors on build.
我已经更新了我的 requirements.txt 以添加请求并删除 pkg-resources,因为它开始在构建时出错。 Contents of requirements.txt
requirements.txt 的内容
click==6.7
点击==6.7
Flask==1.0.2烧瓶==1.0.2
geojson==2.4.0geojson==2.4.0
itsdangerous==0.24它的危险==0.24
Jinja2==2.10Jinja2==2.10
MarkupSafe==1.0标记安全==1.0
pymongo==3.7.1pymongo==3.7.1
pytz==2018.5pytz==2018.5
requests==2.18.4请求==2.18.4
Werkzeug==0.14.1Werkzeug==0.14.1
I was able to deploy the following app:我能够部署以下应用程序:
In app.yaml
:在
app.yaml
:
runtime: python37
handlers:
- url: /static
static_dir: static
- url: /.*
script: auto
In requirements.txt
:在
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
In main.py
:在
main.py
:
from flask import Flask
import pytz
app = Flask(__name__)
@app.route('/')
def hello():
"""Return a friendly HTTP greeting."""
return pytz.VERSION
This successfully returns the version of pytz
.这成功地返回了
pytz
的版本。
Are you sure the new requirements file contains pytz
and is being deployed?您确定新的需求文件包含
pytz
并且正在部署吗? You can check by navigating in the Google Cloud Console to:您可以通过在 Google Cloud Console 中导航来检查:
Resources > App Engine > Services , then in the row with your service, Diagnose > Tools > Source . Resources > App Engine > Services ,然后在您的服务所在的行中, Diagnose > Tools > Source 。 From there you can find the
requirements.txt
file and verify that it contains pytz==2018.5
.从那里您可以找到
requirements.txt
文件并验证它是否包含pytz==2018.5
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.