I'm trying to deploy a Flask app to Heroku.
When I run it locally, it works fine.
But when I deploy it to Heroku and start the dyno, it crashes.
It seem to have a problem with the relative parent package:
The project structure is as follows:
My Procfile is as follows:
web: gunicorn app:app --log-file=-
And this is the line it crashes at:
Why it fails to see that parent package?
Thanks in advance!
Related
I am trying to deploy my dash app which uses dash_extensions, Dash_proxy and has multiple pages in the pages folder on GCP cloud run using gunicorn but the app cannot find the pages folder. It works perfectly fine when I use the development server but breaks in the production server because it cannot find the folder path.
The app (following code is inside the app.py file):
app = DashProxy(use_pages=True, pages_folder=pages_folder, external_stylesheets=[dbc.themes.SIMPLEX])
The app.py file and the pages folder are in the same directory
I have tried tried to following methods to get the folder path:
pages_folder="pages"
pages_folder=os.path.join(os.path.dirname(__file__), "pages")
for p in Path('.').rglob('*'):
if str(p).endswith('pages'):
pages_folder = str(p)
break
None of the above three work in when deploying on gcp using gunicorn through docker:
Dockerfile command:
CMD ["gunicorn" , "-b", "0.0.0.0:8000", "app:server"]
But if I use dev server through docker like following code it works:
CMD python app.py
Does anyone have any ideas of how to make it work with gunicorn?
Thanks for the help!
-Rexon
Yes I did. Just had to specify the root folder. This is what I did and it seems to work for me.
pages_folder=os.path.join(os.path.dirname(__name__), "pages")
app = DashProxy(__name__,use_pages=True, pages_folder=pages_folder, external_stylesheets=[dbc.themes.SIMPLEX])
server=app.server
I am following the instructions here to deploy an app in Google App Engine. Everything works correctly.
Nevertheless, Google, by default, looks for the main folder (where app = Flask(__name__) is defined) in main.py. How could I redefine this? I would like to define this main folder as app.py.
Rename main.py to app.py
Add entrypoint: gunicorn -b :$PORT app:app to your app.yaml file. This is where you are telling Google to find the app object in a file called app
Add gunicorn to your requirements.txt file
Notes:
i. Because you're changing from main.py to app.py, you need to specify an entrypoint. GAE documentation says
If your app meets the following requirements, App Engine will start
your app with the gunicorn web server if you don't specify the
entrypoint field:
The root of your app directory contains a main.py file with a WSGI-compatible object called app.
Your app does not contain Pipfile or Pipfile.lock files.
ii. If you add an entrypoint, then you need to include gunicorn in your requirements.txt file
iii. I just tested the above configuration (the answer I gave) on a dev environment (Python 3.9 environment on Macbook using dev_appserver.py) and it works
I am trying to host a Python\Django app on Heroku. I followed the guide on heroku website but when I execute the line "heroku ps:scale web:1" it comes back the following message:
No process types on ⬢ salty-brushlands-45215.
▸ Upload a Procfile to add process types.
▸ https://devcenter.heroku.com/articles/procfile
I already tryed to commit a Procfile into my project (searching for a solution) but I don't know if requires any configuration inside it. Help please!
Your Procfile should contain this,
web: gunicorn your_project.wsgi
web defines the type of your application
gunicorn is a wsgi server
1.Create .txt file.
2.add this raw to your file:
worker: python main.py
3.save file and delete file extension (.txt)
4.add Procfile to master folder
5.deploy
I have a REST API exposed with Falcon and Waitress. It works fine in my local environment and want to publish it in Heroku.
To start the API, in my Procfile I have the following:
web: waitress-serve --port=$PORT app:api
And I can't see it correctly in the Free Dynos resources.
But when I deploy in Heroku, I get the following error message:
bash: waitress-serve: command not found
I'm using the following Buildpack:
https://github.com/teamupstart/conda-buildpack
In my root folder, I have conda-requirements.txt with waitress==1.3.0
Am I missing anything?
My fix for this was that I had not updated my requirements.txt file with my most recent installs. Do that, git push, and it might work.
I'll add also that my Procfile is this:
web: waitress-serve --port=$PORT --call myapp:create_app
I'm trying to build up a deep-learning-based facebook chatbot (using Python). I'm trying to deploy it on Heroku firstly, but as I'm using the command web: gunicorn echoserver:app the terminal says web: command not found. Howevere, I've installed gunicorn already.
This is because you are typing web:, which is not a command line interface (CLI) command.
If you've installed gunicorn, then the command (from the CLI) is gunicorn. Something like, for instance
gunicorn echoserver:app
I suppose it's also possible that you have a Windows machine. gunicorn does not work on Windows, so you would need to use something like waitress. With waitress, you would type web: on a Windows machine, so that it would be something like
web: waitress-serve echoserver:app
Note that the procfile is literally a file you place in your repository. The contents of the procfile should contain the command you want Heroku to run to start your server.
So in the root directory of your repo, you should have a Procfile (named exactly that with no file extension) with the following contents:
web: gunicorn echoserver:app
The first part (web:) is just used to tell Heroku which dyno to run the second part (the command) on. So Heroku will only run the command on web dynos and not on background dynos.
More info here: https://devcenter.heroku.com/articles/procfile