简体   繁体   中英

ImportError: No module named django.core.wsgi when deploying with nginx

This question asked saverel times. i tried all things but i am unable to solve this error.i am deploying my django app with nginx but getting this error. my wsgi file

import os, sys
# add the hellodjango project path into the sys.path
sys.path.append('/home/ubuntu/webapps/microbird/lib/python2.7/site-packages')


os.environ.setdefault("DJANGO_SETTINGS_MODULE", "microbird.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

i am getting this error

[uWSGI] getting INI configuration from run_microbird.ini
open("./python_plugin.so"): No such file or directory [core/utils.c line 3684]
!!! UNABLE to load uWSGI plugin: ./python_plugin.so: cannot open shared object file: No such file or directory !!!
*** Starting uWSGI 2.0.14 (64bit) on [Tue Mar 21 19:46:25 2017] ***
compiled with version: 4.8.4 on 21 March 2017 14:56:34
os: Linux-3.13.0-108-generic #155-Ubuntu SMP Wed Jan 11 16:58:52 UTC 2017
nodename: ip-172-31-9-49
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /home/ubuntu/webapps
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
chdir() to /home/ubuntu/webapps/microbird
your processes number limit is 7861
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to TCP address 127.0.0.1:3031 fd 3
Python version: 2.7.6 (default, Oct 26 2016, 20:33:43)  [GCC 4.8.4]
Set PythonHome to /home/ubuntu/webapps/env
Python main interpreter initialized at 0x1353e80
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 218280 bytes (213 KB) for 2 cores
*** Operational MODE: preforking ***
Traceback (most recent call last):
  File "microbird/wsgi.py", line 20, in <module>
    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: 21017)
spawned uWSGI worker 1 (pid: 21018, cores: 1)
spawned uWSGI worker 2 (pid: 21019, cores: 1)
*** Stats server enabled on 127.0.0.1:9191 fd: 11 ***

~

my runmicro.ini file is

[uwsgi]
socket = 127.0.0.1:3031
chdir = /home/ubuntu/webapps/microbird
wsgi-file = microbird/wsgi.py
processes = 2
threads = 1
stats = 127.0.0.1:9191
virtualenv = /home/ubuntu/webapps/env
plugin=python
home = /home/ubuntu/webapps/env

~ 

micro_nginx file is

server {

        listen 80 default;

        client_max_body_size 4G;

        # server_name example.com www.example.com;

        server_name microbird.in;

        keepalive_timeout 5;
        error_log /var/log/nginx/error.log;
        #root /home/ubuntu/projects/textproject;

        location / {

        include uwsgi_params;

        uwsgi_pass 127.0.0.1:3031;
        #proxy_pass http://127.0.0.1:8002;
        }

        location /static {

        autoindex on;

        alias /home/ubuntu/webapps/microbird/static;

        }
        location /media {

                alias /home/ubuntu/webapps/microbird/media;

        }
}

Please help me how can i solve this problem

Well, the error is simple:

Traceback (most recent call last):
  File "microbird/wsgi.py", line 20, in <module>
    from django.core.wsgi import get_wsgi_application
ImportError: No module named django.core.wsgi

django isn't on your Python's module search path. To figure out why that is so, I would suggest putting some debug code in your wsgi.py file, here's a start:

import sys

def application(environ, start_response):
    status = '200 OK'

    output = 'sys.path = %s\n' % repr(sys.path)
    output += 'sys.version = %s\n' % repr(sys.version)
    output += 'sys.prefix = %s\n' % repr(sys.prefix)

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]

(under the assumption that either your sys.path or your Python is the reason for django not being found).

If you're trying to use a virtualenv, then you need to activate it. Here's how I do it (in the wsgi.py file):

VIRTUAL_ENV = '/path/to/root/of/virtualenv/'
# activate virtualenv
_activate = "%s/%s/activate_this.py" % (
    VIRTUAL_ENV,
    'Scripts' if sys.platform == 'win32' else 'bin'
)
if sys.version_info >= (3, 0):
    exec(compile(open(_activate, 'rb').read(), _activate, 'exec'))
else:
    execfile(_activate, dict(__file__=_activate))

I'm not sure how well the python 3 branch works (never been used).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM