I already have a Mezzanine app deployed on Heroku. The system ran OK before, but today the web page showed an error message Internal Server Error. Checked with heroku logs and found that the command web python manage.py run_gunicorn -b 0.0.0.0:$PORT -w 1 is deprecated and Heroku suggests using <projName>.wsgi:application.
But Mezzanine currently has different project layout from Django (Mezzanine's settings.py is in the project root directory), so I tried the following in Procfile:
web: gunicorn wsgi --log-file -
However, such a setting results in error message:
ImportError: No module named 'app'
...
ImportError: Could not import settings 'app.settings' (Is it on sys.path? Is there an import error in the settings file?) No module named 'app'.
Then I tried:
web: gunicorn <projName>.wsgi --log-file -
The error message (of course ;-):
ImportError: No module named '<projName>'
So, how do I set Procfile so that gunicorn is able to find the project's settings.py and wsgi.py?
Related
I have following project structure
In Procfile i difine web as web: gunicorn george_paintings.wsgi
When i deploy project on Heroku i see that Heroku identified my Procfile
Starting process with command `gunicorn george_paintings.wsgi`
But when i got an error ModuleNotFoundError: No module named 'george_paintings'
`
How to properly set up wsgi in Proclife in context of my project structure?
Your ModuleNotFoundError: No module named ... error is generally fixed by adding an empty __init__.py file to the folder. See python docs
The init.py files are required to make Python treat directories containing the file as packages
What I would suggest is to remove the application folder and move Procfile, README.md and requirements.txt to the outer george_paintings and use that as your root folder.
Then web: gunicorn george_paintings.wsgi should work as expected.
When I deploy my Django app on Heroku I got following error
Error: No application module specified.
I cleary see that Heroku see wsgi file
Starting process with command `gunicorn --pythonpath application.george_paintings.george_paintings.wsgi --log-file - --log-level debug`
But then I got this error. My Procfile looks like this
web: gunicorn --pythonpath application.george_paintings.george_paintings.wsgi --log-file - --log-level debug
The WSGI
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'george_paintings.settings')
application = get_wsgi_application()
I tried to see logs with
heroku run rails console -a george-paintings
but got an error
bash: rails: command not found
You simply paste cmd
your terminal ( heroku logs --tail ) its shows your error
I have my existing Django application running locally on my MacBook. It's directory structure looks something like this:
myproject/
mySite/
__init__.py
settings.py
urls.py
wsgi.py
myApp1/
__init__.py
models.py
views.py
manage.py
requirements.txt
Up until now, I have been using the Django toy webserver to run my app: ./manage.py runserver 0.0.0.0:8000. But now I want to use gunicorn instead. So I'm following the instructions here.
I do source myVirtualenv/bin/activate && cd myproject && gunicorn mySite.wsgi. I get the following error:
File "/usr/local/Cellar/python/2.7.12_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "myproject/MyApp2/models.py", line 11, in <module>
from caching.base import CachingManager, CachingMixin
ImportError: No module named caching.base
When I run ./manage.py runserver 0.0.0.0:8000 from the same location it works perfectly fine.
Why? Am I doing something wrong?
Does Django-Cache-Machine not work with Gunicorn/WSGI? How to work around this issue?
To run your project using gunicorn, try the following:
activate your virtualenv
go to your project's directory
run gunicorn mySite.wsgi:application --bind 127.0.0.1:8000
If the commands work fine, than my you are setup. Otherwise, try the following tutorial. I always use this tutorial myself, when setting up a new project for production. Try it. Setting up Django with Nginx, Gunicorn and Supervisor
You seem to have installed gunicorn globally rather than within the virtualenv, so the executable is pointing to the global Python and its site-packages directory rather than the one within the virtualenv. Reinstall gunicorn locally.
I have a uWSGI + Nginx set up that is producing the following error:
django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model 'accounts.CustomUser' that has not been installed
The error message is showing that virtualenv is picked up fine, as are other apps within my project apps/ folder.
If I run the same site via django-admin.py runserver then the error does not occur.
I have my project based on the django startproject: https://github.com/lincolnloop/django-startproject/
Here is my procfile:
web: gunicorn <myproject>.wsgi:application
Right now I have my set up like this:
[myproject]
---[conf]
------[local]
---------settings.py
------[qa]
---------settings.py
---[server_configs]
------[local]
---------django.wsgi
------[qa]
---------django.wsgi
My django.wsgi looks like this:
import os
import sys
import django.core.handlers.wsgi
sys.path.append('/app')
sys.path.append('/app/myproject')
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.conf.qa.settings'
application = django.core.handlers.wsgi.WSGIHandler()
I want to use the qa/django.wsgi for Heroku, but I am getting an error saying:
ImportError: No module named [myproject].wsgi
I have already gone through and tried solutions in this post: Configuring gunicorn for Django on Heroku but with no luck on my end.
Right now my PYTHONPATH is /app and have already tried Gunicorn+Django+Heroku. Python Path Issue with no luck either.
I had a similar problem once. Basically, you're running gunicorn from your root directory, but your wsgi is in [my_project]/[server_configs]/[qa]/.
There are two ways to go about it. If each of those directories has an init.py file, you can call it like a normal python module. Use:
web: gunicorn [myproject].[server_configs].[qa].django.wsgi:application
If they don't have init.py files (I didn't), you'll need your Procfile to switch into the proper directory. Try:
web: sh -c 'cd [server_configs]/[qa] && gunicorn django.wsgi:application'
Basically this is running a command in your shell to (1) change directories and (2) run gunicorn.
Heroku allows you to use environment variables in your Procfile. If you define an environment variable on Heroku, like so: heroku config:set WSGI_PATH=path/to/my/file/wsgi.py, then in your Procfile do: gunicorn $WSGI_PATH:application you should be good to go!