Heroku Error: No application module specified. Django - django

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

Related

uwsgi in virtualenv but attach-daemon for django doesn't get venv

I'm building a django project (mailman3) and accessing it with uwsgi. I have it running successfully when launching uwsgi within the virtualenv from the command line.
I'm trying to build a systemd service to manage uwsgi. It successfully loads the virtual environment for uwsgi and runs. But when it tries to run the django process with attach-daemon, manage.py can't find the django module, i.e., it's not picking up the virtual environment.
In the /etc/uwsgi.ini file I have:
virtualenv = /opt/mailman/venv
chdir = /opt/mailman/mailman-suite/mailman-suite_project
attach-daemon = ./manage.py qcluster
The systemd service has:
ExecStart=/opt/mailman/venv/bin/uwsgi --ini /etc/uwsgi.ini
When systemd starts the service, my error log reports:
[...]
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x558c5945bc30 pid: 15392 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 15392)
spawned uWSGI worker 1 (pid: 15416, cores: 2)
Traceback (most recent call last):
File "./manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'
Here's the puzzle piece:
It worked running locally with the virtualenv active. But when run by systemd, even using uwsgi from within the virtualenv, the attach-daemon process would not inherit the virtualenv.
Changing the config line to the following enables the virtualenv:
attach-daemon = /opt/mailman/venv/bin/python3 ./manage.py qcluster

Having trouble getting django heroku to run properly. How do I resolve error code=H14 desc="No web processes running"?

I have previously ran this app on Heroku without issues. But it had been around 6 months since I deployed and I also switched computers from a Linux to a Windows machine.
Now when I deploy, the deployment is successful but the service does not work. When I check the logs the error is:
code=H14 desc="No web processes running"
I have not changed the Procfile or the requirements.txt since it had been working
requirements.txt:
django
gunicorn
django-heroku
requests
djangorestframework
django-cors-headers
flask-sslify
Procfile:
release: python manage.py migrate
web: gunicorn findtheirgifts.wsgi --log-file -
wsgi.py
"""
WSGI config for findtheirgifts project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "findtheirgifts.settings")
application = get_wsgi_application()
I have tried some suggestions from similar threads
heroku ps:restart
heroku buildpacks:clear
heroku ps:scale web=1
None of which seemed to change anything. Any help on this would be greatly appreciated!
As the error indicates, your app doesn't have any web process running.
You can see all running processes from the CLI with the following command:
heroku ps -a <your app name>
And scale your web process to 1 with the following:
heroku ps:scale web=1 -a <your app name>
Which will start one instance of your app.
See the Heroku Scaling Documentation.
Turns out in initialized the heroku git file in a different directory than I had previously. Causing the app to not find the Procfile.

django: uwsgi not running with supervisor

This is my uwsgi ini file,
[uwsgi]
chdir=/root/projects/cbapis/cbapis
module=cbAPIs.wsgi:application
env = DJANGO_SETTINGS_MODULE=cbAPIs.settings.production
http=0.0.0.0:8002
workers=1
home=/root/projects/cbapis/cbapis/env
This is the django wsgi file,
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cbAPIs.settings.production")
application = get_wsgi_application()
When I run server with uwsgi, it runs fine,
uwsgi --ini cbapi_uwsgi_config.ini
Below is my supervisor conf for this project,
[program:djangocbapis]
command=uwsgi --ini /root/cbapi_uwsgi_config.ini
environment =
DJ_DEV_SERVER_DB_NAME="****",
DJ_DEV_SERVER_DB_USER="****",
DJ_DEV_SERVER_DB_HOST="*****",
DJ_DEV_SERVER_DB_PASSWORD="*****",
autostart=true
autorestart=true
user=root
priority=400
stderr_logfile=/var/app/cbapis/log/cbapis.log
When I run this uwsgi server via supervisor, it does not run. I get the following error in the log file,
--- no python application found, check your startup logs for errors ---
I have similar supervisor and uwsgi configuration for my other django projects in the same server, which are running fine with supervisor and uwsgi.
But I can't figure out why it cannot find python application while running with supervisor.
So, please help me in this matter.
Try to give full path to uwsgi like /usr/bin/uwsgi or /usr/local/bin/uwsgi. If you are on ubuntu/linux then type command which uwsgi to get full path. It will work.
[program:djangocbapis]
command=/usr/bin/uwsgi --ini /root/cbapi_uwsgi_config.ini
autostart=true
autorestart=true
user=root
priority=400
stderr_logfile=/var/app/cbapis/log/cbapis.log
setup the environment variable in uwsgi .ini file.
env = DJ_DEV_SERVER_DB_NAME="****",
env = DJ_DEV_SERVER_DB_USER="****",
env = DJ_DEV_SERVER_DB_HOST="*****",
env = DJ_DEV_SERVER_DB_PASSWORD="*****",

How to set `Procfile` for a Mezzanine app deployed on Heroku

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?

Django and gunicorn: Specify path to django.wsgi file in environment specific folders for Heroku

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!