Google Compute Engine doesn’t recognize main.py

Viewed 49

I'm trying to deploy a Flask app on Google Compute Engine. I have it all configured, but when I try to deploy it with gcloud app deploy, it says ModuleNotFoundError: No module named 'main'. This is my file structure:

└── gpt-redteam-api/
    ├── app.yaml
    ├── main.py
    └── ...other files

and I am deploying it from inside gpt-redteam-api. Is this a common problem/are there any elementary fixes I’m missing?

1 Answers

For your issue you need to add a custom entrypoint to recognize the main.py

Entrypoint: Optional. Overrides the default startup behavior by executing the entrypoint command when your app starts. For your app to receive HTTP requests, the entrypoint element should contain a command which starts a web server that listens on port 8080.

You need to configure the entrypoint field by the following steps.

This line says to look for the variable named app in the module named main.py:

entrypoint: gunicorn -b:$PORT main:app

You could either rename your app.py to main.py or update this line to:

entrypoint: gunicorn -b:$PORT app:app

For more information follow this doc and refer to this stack question also.

Related