I'm reading a book about TDD and Django and there's a deployment part. I have a problem trying to run gunicorn with the following command:
/root/sites/django_blog/virtualenv/bin/gunicorn --bind unix:/tmp/django_blog.socket django_blog.wsgi:application
It fails with the following error:
ModuleNotFoundError: No module named 'django_blog'
But when I activate my virtualenv and instead of writing the full pass to gunicorn I just go with:
gunicorn --bind unix:/tmp/django_blog.socket django_blog.wsgi:application
And everything works perfectly! The problem is I still need to run it the first way, because I wil use it in the nginx service file. I wrote about this error and tried a couple of solutions but they didn't work for me. I guess I have to do something with environment variables but I don't know what exactly.
You can specify a directory to gunicorn to switch to before the apps are loaded.
Simply add --chdir /path/to/directory to the launch.
In your case this might look as follows:
/root/sites/django_blog/virtualenv/bin/gunicorn --chdir /root/sites/django_blog/source --bind unix:/tmp/django_blog.socket django_blog.wsgi:application
Here is the link to the specific gunicorn settings documentation.
Hope that helps and happy coding!
Related
first time deploying to heroku. I got the test app deployed and I ran the migrations fine. However, I got the following error
ModuleNotFoundError: No module named 'djorg2'
I ran heroku logs --tail and got the following result here
here is the a pic of my file paths
and here is my current Procfile
web: gunicorn djorg2.wsgi --log-file -
I'm a little new to deploying on heroku. Does anyone know what my problem might be and/or count point me in the right direction. I been trying to trouble shoot this for the good part of an afternoon and I'm a little stuck.
web: gunicorn practice.djorg2.wsgi --log-file -
Thanks for the tips everyone. I had a feeling it was probably due to file placement. I re-organized my files so that everything was at the root of my git repo and it works fine now.
I think I'm going to put everything in its own file location from now on just to be more organized and not confuse myself. I did try
web: gunicorn practice.djorg2.wsgi --log-file -
but for some weird reason it didn't work.
I am following this tutorial http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html to setup django with nginx and uwsgi. But I am confused about this line:
uwsgi --http :8000 --module mysite.wsgi
In the tutorial there's nothing about mysite.wsgi file. What should be the content of this file?
Actually, that's not a filename.
That's a python module path.
The relevant file is actually mysite/wsgi.py (but to import it in a python interpreter, you'd have to import mysite.wsgi, hence the name used in command line).
I am getting this error when i am trying to run
python manage.py runserver for my Django Project,
newrelic.api.exceptions.ConfigurationError: Configuration has already been done against differing configuration file or environment. Prior configuration file used was "/home/project/newrelic.ini" and environment "staging".'
What does it mean ?? How to approach it?
Have you just setup New Relic?
I believe this is a problem with your procfile. Which you most likely just have edited.
Your procfile should look something like this, depending on your wsgi.
web: newrelic-admin run-program gunicorn hello.wsgi --log-file -
I'm trying to setup a test Django project on Heroku. Following the advice here and in the Heroku Getting Started I'm trying to use gunicorn instead of the Django dev server.
This was my first attempt at the Procfile:
web: gunicorn_django --workers=4 --bind=0.0.0.0:$PORT my_project/settings.py
worker: python my_project/manage.py celeryd -E -B --loglevel=INFO
This gave me this error:
ImportError: Could not import settings 'settings.py' (Is it on sys.path?): No module named py
I decided to take a different track and followed the advice here. Now my Procfile looked like this:
web: gunicorn_django -b 0.0.0.0:\$PORT -w 9 -k gevent --max-requests 250 --preload my_project.settings
(I also updated my requirements file to include gevent.) It gave me the same error:
ImportError: Could not import settings
Finally, I just set it to settings:
web: gunicorn_django -b 0.0.0.0:\$PORT -w 9 -k gevent --max-requests 250 --preload settings
But now I get this error:
Error: django project not found
The way my Django project is set up is that the settings.py file is in the parent directory of the repo -- I don't have the Django project under another directory. It's at the same level as the virtualenv and git files. Would that be a problem? I'm sure I'm doing something simple wrong -- any help would be much appreciated.
If I follow the instructions from Heroku here and change the Procfile to this:
web: gunicorn hellodjango.wsgi -b 0.0.0.0:$PORT
Nothing happens -- no errors in the logs, but no proceses run and the app just appears dead in the water.
I have just run into this same issue. In the procfile you copied from the Heroku guide, change hellodjango.wsgi to yourproject.wsgi
Looks like we all fall victim to blindly copy-pasting now and then, but in your (and my) defense, it looks like there's no *.wsgi file that's actually being opened, it's just how you signal to gunicorn that you want it to run your django project.
I had the same exact issue that you are having. The way I was able to finally get it working was to use the django app gunicorn.
I added gunicorn to the django settings.py
'gunicorn',
I then used this as my web entry in my Procfile.
web: python manage.py run_gunicorn -b 0.0.0.0:\$PORT -w 9 -k gevent --max-requests 250 --preload
You may have to alter you .manage.py if you use a different directory structure then I did. My app was in /app, and my python path was also /app.
I had this issue and landed up having to point directly to the python path and then set the settings reference.
In the end my Procfile looks like this:
web: gunicorn_django --pythonpath=/app/project --settings=settings
I had to run heroku run which showed the env variables and that's where I was able to find the /app which I prepended to my project name.
Do you have a requirements.txt in the root folder (containing the word django), as well as a settings.py? Those appear to the be the requirements for Django app detection, as documented here.
I have a problem when I use django with uwsgi with the pythonpath.
I have a django project named 'project' which is the /sites/django/ directory
So to start uwsgi i use this command :
/opt/uwsgi/uwsgi -s 127.0.0.1:9001 -C -M 4 -t 30 -A 4 -p 4 -d /var/log/uwsgi.log --pythonpath '/sites/django/project/' --module wsgi
If I am in the /sites/django/project' it works.
If I start a python shell and I write :
import sys
sys.path.append('/sites/django/project/')
import wsgi
It works too.
But when i launch the uwsgi command outside the /sites/django/project/ I have the error :
ImportError: No module named wsgi
So I don't know why I have the ImportError : it works in the shell.
If anyone has an idea,
Thanks.
Well, i find the answer, it seems it's a bug and i must add the "-i" option (single interpreter mode ) in my command .
The documentation seems to suggest two possibilities.
First, remove the single quotes from the python path argument. Second, the examples on the linked page have --python-path instead of --pythonpath (even though the index at the top of the page says otherwise). Worth trying.
if you're using a virtualenv, you need to pass in the -H flag ( http://projects.unbit.it/uwsgi/wiki/VirtualEnv )