My Problem:
When using gunicorn as my WSGI HTTP server, foreman fails to find the Django (wsgi?) application.
Application Structure:
In my Django application, I have things structured like this:
<git_repository_root>/
<django_project_root>/
<configuration_root>/
The <git_repository_root> contains the project management and deployment related things (requirements.txt, Procfile, fabfile.py, etc.)
The <django_project_root> contains my Django apps and application logic.
Finally, the <configuration_root> contains my settings.py and wsgi.py.
What I have tried:
My Procfile should look like this (according to the Heroku Docs):
web: gunicorn myapp.wsgi
When running foreman start with this project layout, I get an error:
ImportError: Import by filename is not supported.
What works:
If I move my Procfile from <git_repository_root> to <git_repository_root> it works locally. After pushing to Heroku (note: Heroku sees <git_repository_root>) I can't scale any workers / add processes. I get the following:
Scaling web dynos... failed
! No such process type web defined in Procfile.
I believe I want Procfile in my <git_repository_root> anyway though - so why isn't it working? I also tried changing the Procfile to:
web: gunicorn myapp/myapp.wsgi
but no luck. Any help would be much appreciated!
Treat the entry in your Procfile like a bash command. You can cd into your <django_project_root> and then run the server.
For example, your Procfile (which should be in your <git_repository_root>) might look something like this:
web: cd <django_project_root> && gunicorn
--env DJANGO_SETTINGS_MODULE=<configuration_root>.settings
<configuration_root>.wsgi
Move your Procfile back to <git_repository_root> and use:
web: gunicorn <django_project_root>.myapp:myapp
replacing the final "myapp" with your app's class name, presumably it is indeed "myapp".
... and read the error message: it is telling you that you can't import your worker class (app) by filename (myapp.wsgi), so of course saying dirname/myapp.wsgi won't work as well. You need a Python module:class syntax.
Related
i'm kind of new to Heroku, but got a question in relation to dynos.
My situation is as follows. I'm running on main application in django that runs the following dyno command
"web gunicorn DJANGO_WEBPAGE.wsgi --log-file - ", and inside my main project there is a streamlit app that runs the following command
"streamlit run geo_dashboard.py", but it seems i can't run both commands on the same dyno.
1.- Is there a way to accomplish this?
2.- Do they need to be on separate apps?
3.- In case of limitations do to being a free user, does the hobby plan covers it?
I've tried running my procfile this way
web: gunicorn DJANGO_WEBPAGE.wsgi --log-file - && web: sh setup.sh && streamlit run geo_dashboard.py
Even though i get no errors, only the streamlit app appears leaving the django app shutdown.
When I deploy my Django app to Heroku, in the console (heroku logs --tail -a george-paintings) I see an error:
2021-04-15T15:14:42.109272+00:00 app[web.1]: Error: No application module specified.
2021-04-15T15:14:42.161597+00:00 heroku[web.1]: Process exited with status 1
2021-04-15T15:14:42.290903+00:00 heroku[web.1]: State changed from starting to crashed
But I can't figure out what particular went wrong. My Procfile looks like this
web: gunicorn --pythonpath application.george_paintings.george_paintings.wsgi --log-file - --log-level debug
Where can I find more info about my error?
I suspect there's nothing more to see. A good first step would be to try running heroku local to see if you are having the same problem on your development machine. This will use your Procfile whereas if you are running via python manage.py migrate or similar your Procfile will not be used.
The error gives a good hint, though:
app[web.1]: Error: No application module specified.
Gunicorn expects an application module name as a command-line argument. I suspect you intend application.george_paintings.george_paintings.wsgi to be interpreted as your application module, but it's getting swallowed up as an argument to --pythonpath:
gunicorn --pythonpath application.george_paintings.george_paintings.wsgi #...
You shouldn't need to explicitly provide a PYTHONPATH. Try removing that argument from your Procfile entirely:
gunicorn application.george_paintings.george_paintings.wsgi --log-file - --log-level debug
If this works locally with heroku local, commit the change and redeploy.
If not, take a look at your directory structure. application.george_paintings.george_paintings.wsgi is a bit of a weird module name for a Django project. Usually you'd just need something like george_paintings.wsgi (indicating that Gunicorn should use the Python module it finds at george_paintings/wsgi.py as its entry point).
I'm running a Django website in a Vagrant box that (roughly) mirrors a Heroku set-up. It uses Foreman with a Procfile like this:
web: gunicorn projectname.wsgi > /vagrant/gunicorn.log 2>&1
However, when I change my Django code, the server doesn't restart or reload the code, which makes development... painful!
How can I make Foreman serve the new code when it changes?
According to the Heroku site when I get error H14 "No Web Processes Running" it's because I need to scale up dynos by:
heroku ps:scale web=1
However, when I do that I get the following error:
Scaling web processes... failed
! No such type as web
Does anyone know how to fix this? I want to get my site back up!
When I run heroku ps I see nothing.
UPDATE: It's not detecting my Procfile. I don't have a Procfile explicitly and didn't use one before... is it absolutely necessary?
I ran into this recently as well, my web was working fine without any Procfile, until recently...
My fix was simply to add a Procfile as follows:
web: python manage.py runserver 0.0.0.0:$PORT --noreload
Then push to heroku.
For Heroku you need to add a Procfile.
add a Procfile on same level like your manage.py file. It should be in your root directory. Be sure that you create a Procfile not a Procfile.txt or else just Procfile
in your Procfile add:
web: gunicorn projectname.wsgi
add in your requirements.txt gunicorn
gunicorn==20.0.4
If you activate automatic deploy you can try it again.
If you can remove the app, remove it and deploy it again.
Followed the "Getting started with Django on heroku/ceadar" guide to the letter and FINALLY managed to sort out some issues on app deployment
Successfully installed django psycopg2
Cleaning up...
Discovering process types
Procfile declares types -> (none)
Compiled slug size is 8.0MB
Launching... done, v4
http://<watever>.herokuapp.com deployed to Heroku
and the guide says the webserver should be up. but heroku ps shows no processes, and obviously the page doesnt load.
tail of the heroku log:
2012-01-19T10:28:29+00:00 heroku[web.1]: State changed from created to down
2012-01-19T10:28:30+00:00 heroku[web.1]: State changed from down to created
2012-01-19T10:28:32+00:00 heroku[slugc]: Slug compilation finished
2012-01-19T10:30:32+00:00 heroku[router]: Error H99 (Platform error) -> GET <watever>
.herokuapp.com/ dyno= queue= wait= service= status=503 bytes=
(venv) C:\Python27\facebook\venv\myapp>heroku ps
Process State Command
------- ----- -------
should I be starting the webserver explicitly? wat am I doing wrong?
The Procfile I use for my django/heroku instance looks like this:
web: python hellodjango/manage.py runserver "0.0.0.0:$PORT"
As has been mentioned, if you have no Procfile and you're using the default webserver, it will essentially do the above - but try being explicit. You can try running it from the heroku console instead, to see what (if any) errors it gets:
heroku run python hellodjango/manage.py runserver
I just ran into the same problem, although I don't know if it was for the same reason or not.
While executing this command from the tutorial:
django-admin.py startproject hellodjango .
I changed the name of the app to something else (not just in this command, of course), but I omitted the '.' at the end. This caused the script to create an app inside a directory of the same name rather right in the directory I was in and that caused Heroku's server-side script to fail to detect the app as a Django app.
I ran into this problem as well. Make sure your Procfile looks correct by running...
$heroku run bash
to open a terminal with access to heroku. And then...
$cat Procfile
This will show you what is actually in your Procfile. The first line (in my local file) in mine wasn't being read for some reason. Then, I had a "}" appended to my file. I was creating my file in TextEdit on a Mac - should have been using SublimeText or another text editor. You can also call
$echo "web: gunicorn hello:app" >> Procfile
Or whatever you want your Procfile to say. This will change your Procfile to whatever you echo.
I've been struggling with Django on Heroku for some time and decided to put together a very opinionated but functioning bootstrap. I hope it can help others along the road: https://github.com/callmephilip/django-heroku-bootstrap
The key is here:
Procfile declares types -> (none)
Heroku doesn't know how to run your application. I assume python hellodjango/manage.py runserver works locally for you? If so, Heroku should be able to pick this up.
Also check that you have a requirements.txt in the repo root, and a settings.py in one of your project subdirectories.