uwsgi + nginx + Django : ImportError: No module named django.core.wsgi
Solution 1
your module is pointed to your project, shouldn't it be pointed to your projects main app that way it can find the wsgi file?
so on my INI file looks like this.
In my particular case I'm using a virtual environment, django 1.7 and uwsgi.
vhost = true
plugins = python
socket = /tmp/noobmusic.sock
master = true
enable-threads = true
processes = 2
wsgi-file = /home/myname/webapps/music/music/music/wsgi.py
virtualenv = /home/myname/webapps/music/musicenv/
chdir = /home/myname/webapps/music/music/
this is the only site I've ever setup uwsgi as I typically use mod-wsgi and unfortunately do not remember all the steps.
Solution 2
I had similar issue. Solved it -after many hours- by making sure that uwsgi is installed using same python version (2 / 3) as the python version of your virtualenv. Otherwise it will not use your virtualenv and thus start throwing 'can not find module xyz' kind of errors. To install uwsgi under python3 you have to use pip3 (which in turn might need to be installed with something like 'apt-get install python-pip3'). When calling uwsgi on cli or via .ini file you need to reference your virtualenv mentioning the full path (which ends one folderlevel above the folder in which the /bin/ is; so /example/myvenv/bin/activate means the full path is /example/myvenv.
I made the uwsgi install global so outside of my virtualenv. I suppose above applies/would work as well when installing uwsgi within the virtualenv, but have not tried (yet).
Solution 3
Keep the system-wide uwsgi
the same version as your virtual environment python.
In my environment, my virtual environment is python3.7, but the system default python is python3.6.
After I uninstall uWSGI
, and re-install the system-wide uWSGI
with python3.7, the problem has been resolved.
sudo pip uninstall uwsgi
sudo -H python3.7 -m pip install uwsgi
jaysonpryde
Updated on June 27, 2022Comments
-
jaysonpryde almost 2 years
I am trying to deploy a Django app using nginx + uwsgi. I created a virtual environment (virtualenv), and installed both uwsgi and Django inside the virtual env (i.e.local to the virtual environment). I have no global Django and uwsgi. When I run the uwsgi --ini project.ini, I am having an 'ImportError: No module named django.core.wsgi' exception:
from django.core.wsgi import get_wsgi_application ImportError: No module named django.core.wsgi unable to load app 0 (mountpoint='') (callable not found or import error) *** no app loaded. going in full dynamic mode *** *** uWSGI is running in multiple interpreter mode *** spawned uWSGI master process (pid: 5987) spawned uWSGI worker 1 (pid: 5988, cores: 1) spawned uWSGI worker 2 (pid: 5989, cores: 1) spawned uWSGI worker 3 (pid: 5990, cores: 1) spawned uWSGI worker 4 (pid: 5991, cores: 1)
Based on my search, it's recommended to put env and pythonpath variables in the ini if you are using Django1.5 or lower. However, I am using Django 1.7, so I did not place them anymore. Here's my project.ini:
#project.ini file [uwsgi] # Django-related settings # the base directory (full path) chdir = /root/virtualenv/project # Django wsgi file module = project.wsgi:application # the virtualenv (full path) home = /root/virtualenv # process-related settings # master master = true # maximum number of worker processes processes = 4 # the socket (use the full path to be safe socket = /root/virtualenv/project/project.sock # ... with appropriate permissions - may be needed chmod-socket = 666 chown-socket = root:root # clear environment on exit vacuum = true # other config options uid = root gid = root processes = 4 daemonize = /var/log/uwsgi/project.log no-site = True
How will i fix this? I'm quite stuck on this for a day already. Any ideas are greatly appreciated. Thanks in advance!
-
jaysonpryde about 9 yearswhich variable is that?
-
Chris Hawkes about 9 years# Django wsgi file module = project.wsgi:application
-
jaysonpryde about 9 yearsi think it can find my wsgi file because chdir is set to /root/virtualenv/project. When this directory is entered, wsgi.py is located in project (so /root/virtualenv/project/project/wsgi.py). Thanks anyway
-
Chris Hawkes about 9 yearsI updated my answer to provide an example of what my .ini file looks like. Unfortunately I'm not that experienced running uwsgi behind virtualenv. but I do have this site successfully working.