ModuleNotFoundError - No module named 'main' when attempting to start service

后端 未结 4 561
梦毁少年i
梦毁少年i 2020-12-11 15:21

Context:

  • I created a Django application using Python 3.7.
  • I am (attempting) to use the 2nd generation Google App Engine standard environment.
4条回答
  •  孤城傲影
    2020-12-11 15:53

    By default, App Engine looks for an app variable in a file called main.py. You have two options: put your WSGI app where App Engine expects it to be, or define a custom entrypoint:

    Put your WSGI app where App Engine expects it to be:

    You can create a file called main.py that has an app variable which is simply imported and aliased from the correct location:

    from demosite.wsgi import main as app
    

    Adding a custom entrypoint:

    From https://cloud.google.com/appengine/docs/standard/python3/config/appref:

    entrypoint: Optional. The command that is executed when your app starts. For your app to receive HTTP requests, entrypoint should contain a command which starts a web server that listens on the port specified by the PORT environment variable. If you do not specify an entrypoint, App Engine will configure and start the Gunicorn webserver.

    By default it's this:

    entrypoint: gunicorn -b :$PORT main:app
    

    You would need something like:

    entrypoint: gunicorn -b :$PORT demosite.wsgi:main
    

    See here for more details about application startup: https://cloud.google.com/appengine/docs/standard/python3/runtime#application_startup

提交回复
热议问题