Heroku Django Gunicorn 'Foreman Start' error - django

I'm working through the Heroku's Django tutorial and I got all the way down to 'Using a different WSIG server'.
When I try to use gunicorn I get the following error:
requirements.txt
Django==1.4.1
distribute==0.6.28
dj-database-url==0.2.1
psycopg2==2.4.5
gunicorn==0.14.6
Procfile
web: gunicorn djtut.wsgi -b 0.0.0.0:$PORT
(venv) C:\Users\xxxx\Documents\Python\djtut>foreman check
valid procfile detected (web)
(venv) C:\Users\xxxx\Documents\Python\djtut>foreman start
10:53:05 web.1 | started with pid 5652
10:53:06 web.1 | exited with code 1
10:53:06 web.1 | Traceback (most recent call last):
10:53:06 system | sending SIGKILL to all processes
10:53:06 | File "C:\Users\xxxx\Documents\Python\djtut\venv\Scripts\
gunicorn-script.py", line 9, in <module>
(venv) C:\Users\xxxxx\Documents\Python\djtut>
Works fine using the dev server on Heroku. I'm on Windows 7. Any ideas? I suspect it is an OS issue?
thanks,
AP

Unfortunately, Gunicorn doesn't work on Windows.

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

Django runserver on Docker does not respond when opened in the browser

I am just a beginner at this
So when I run
sudo docker-compose run web python manage.py runserver
it shows
Starting thirddj_db_1 ... done
usr/local/lib/python3.6/site-packages/psycopg2/__init__.py:144:
UserWarning: The psycopg2 wheel package will be renamed from release
2.8; in order to keep installing from binary please use "pip install
psycopg2-binary" instead. For details see:
<http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
""")
/usr/local/lib/python3.6/site-packages/psycopg2/__init__.py:144:
UserWarning: The psycopg2 wheel package will be renamed from release
2.8; in order to keep installing from binary please use "pip install
psycopg2-binary" instead. For details see:
<http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
""")
Performing system checks...
System check identified no issues (0 silenced).
April 11, 2018 - 19:15:59
Django version 1.11.12, using settings 'composeexample.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
And then when I opened it in my browser, it shows the site cant be reached
But when i run
docker-compose up
it shows
web_1 | /usr/local/lib/python3.6/site-
packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel
package will be renamed from release 2.8; in order to keep installing
from binary please use "pip install psycopg2-binary" instead. For
details see: <http://initd.org/psycopg/docs/install.html#binary-
install-from-pypi>.
web_1 | """)
web_1 | /usr/local/lib/python3.6/site-
packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel
package will be renamed from release 2.8; in order to keep installing
from binary please use "pip install psycopg2-binary" instead. For
details see: <http://initd.org/psycopg/docs/install.html#binary-
install-from-pypi>.
web_1 | """)
web_1 | Performing system checks...
web_1 |
web_1 | System check identified no issues (0 silenced).
web_1 | April 11, 2018 - 19:21:41
web_1 | Django version 1.11.12, using settings
'composeexample.settings'
web_1 | Starting development server at http://0.0.0.0:8000/
web_1 | Quit the server with CONTROL-C.
And then when I opened it in my browser, it works
so i want to know Why sudo docker-compose run web python manage.py runserver is not working and what is the difference between both commands.
and here is my docker-compose file
version: '3'
services:
db:
image: postgres
web:
build: .
command: python3 manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
When you run the web container it's necessary run command with the service's ports enabled and mapped to the host.
Try this:
sudo docker-compose run --service-ports web python manage.py runserver

Foreman start only has one line for Django and heroku

I install the heroku toolbelt from the website and use pip to install django toolbelt on both mac and ubuntu vm copy.
Both of them only return one line when using foreman start:
Procfile:
web: gunicorn hero.wsgi
foreman start:
23:44:46 web.1 | started with pid 4382
Ctrl+C and I got:
23:47:36 system | sending SIGTERM to all processes
23:47:36 web.1 | terminated by SIGTERM
I have read about the https://github.com/ddollar/foreman/wiki/Missing-Output
and did:
script.py:
PYTHONUNBUFFERED=True
and run it with python -u script.py
What am I doing wrong? Any advice will be appreciated.

No resources found error after deploying Django app

I'm trying to deploy my app to Heroku using this tutorial:
https://devcenter.heroku.com/articles/getting-started-with-django#deploy-to-heroku
I managed to push my app to Heroku, but I keep getting this error when I try to make sure I have at least one dyno running:
(tapeworm_django)Christophers-MacBook-Pro-2:tapeworm christopherspears$ heroku ps:scale web=1
Scaling dynos... failed
! No app specified.
! Run this command from an app folder or specify which app to use with --app APP.
(tapeworm_django)Christophers-MacBook-Pro-2:tapeworm christopherspears$ heroku ps:scale web=1 --app tapeworm
Scaling dynos... failed
! Resource not found
I ran the command inside the same directory as my Procfile:
/Users/christopherspears/PyDevel/tapeworm_django
(tapeworm_django)Christophers-MacBook-Pro-2:tapeworm_django christopherspears$ ls *
README.md requirements.txt
tapeworm:
Procfile drawings/ manage.py* tapeworm/ templates/
Any hints?
UPDATE:
I can get it to run locally:
(tapeworm_django)Christophers-MacBook-Pro-2:tapeworm christopherspears$ foreman start
16:43:17 web.1 | started with pid 2366
16:43:17 web.1 | 2014-03-29 16:43:17 [2366] [INFO] Starting gunicorn 18.0
16:43:17 web.1 | 2014-03-29 16:43:17 [2366] [INFO] Listening at: http://0.0.0.0:5000 (2366)
16:43:17 web.1 | 2014-03-29 16:43:17 [2366] [INFO] Using worker: sync
16:43:17 web.1 | 2014-03-29 16:43:17 [2369] [INFO] Booting worker with pid: 2369
I managed to get this to work. First, I moved my Procfile up a level, so my project is structured like so:
tapeworm_django/
Procfile
README.md
requirements.txt
tapeworm/
drawings/ <- app
manage.py
tapeworm/ <- project configuration folder
templates/
I moved the Procfile up a level because I see that most developers seem to place the file in the root directory. Am I wrong?
Then I changed the contents of the file to from
web: gunicorn tapeworm.wsgi
to
web: python tapeworm/manage.py runserver 0.0.0.0:$PORT --noreload
I am unsure if that solution is considered "proper" because it seems to clash with the Getting Started With Django tutorial:
https://devcenter.heroku.com/articles/getting-started-with-django

Trying to test django app locally with foreman

I'm working on a django app and trying to use foreman to test my app locally before pushing to heroku. I can successfully run it using python manage.py server. However when running it using forman it fails - Whenever I do a foreman start inside of the directory it would return me this:
09:21:09 web.1 | started with pid 9956
09:21:09 web.1 | /usr/local/foreman/bin/foreman-runner: line 41: exec: gunicorn: not found
09:21:09 web.1 | exited with code 127
09:21:09 system | sending SIGTERM to all processes
SIGTERM received
What does this mean?
Below is my Procfile:
web: gunicorn myapp.wsgi
Below is my requirements.txt
Django==1.4.3
distribute==0.6.31
dj-database-url==0.2.1
psycopg2==2.4.6
#wsgiref==0.1.2
gunicorn==0.16.1
Thanks for the help in advance!
It looks like gunicorn isn't installed properly on your system.
Run pip install -r requirements.txt and then manually run the gunicorn command to check it works.
I came to this question with the same problem finding gunicorn when running 'foreman start', but eventually dug up at other sources that I was not recreating the virtualenv in a new bash session. I had originally followed the instructions from Heroku, but days later with new sessions, needed to remember to run
source venv/bin/activate
Had the issue - installing separately gunicorn did the trick
pip install gunicorn
I had the same issue:
sudo apt-get install libpq-dev python-dev
and then reinstalling the heroku-toolbelt solved it!