2021年5月1日星期六

Google Cloud Run No module named 'main'

I am trying to run a Flask app using Google Cloud Run. I first created a service using the steps here. Then, I clicked "Set up Continuous Deployment", linked it to my GitHub repository, chose the option to use a Google Cloud Buildpack, and used the default entrypoint. I even tried typing it myself. Here is how the app is organized:

server.py - Has the flask app

from flask import Flask, jsonify, request    app = Flask(__name__)    @app.route("/")  def index():      return jsonify({"Message": "This is a REST API"})    if __name__ == '__main__':      app.run()  

main.py - Has this one line: from server import app

However, I still get this log output:

Traceback (most recent call last):    File "/usr/local/lib/python3.7/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker      worker.init_process()    File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/base.py", line 134, in init_process      self.load_wsgi()    File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi      self.wsgi = self.app.wsgi()    File "/usr/local/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi      self.callable = self.load()    File "/usr/local/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 58, in load      return self.load_wsgiapp()    File "/usr/local/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp      return util.import_app(self.app_uri)    File "/usr/local/lib/python3.7/site-packages/gunicorn/util.py", line 359, in import_app      mod = importlib.import_module(module)    File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module      return _bootstrap._gcd_import(name[level:], package, level)    File "<frozen importlib._bootstrap>", line 1006, in _gcd_import    File "<frozen importlib._bootstrap>", line 983, in _find_and_load    File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked  ModuleNotFoundError: No module named 'main'  

I saw from other SO posts that this is usually because there is no main.pt file. However, I clearly have it in the repository. Is there anything I'm doing wrong? Any help is appreciated, Thank You in advance!

https://stackoverflow.com/questions/67352020/google-cloud-run-no-module-named-main May 02, 2021 at 08:32AM

没有评论:

发表评论