简体   繁体   English

ImportError:使用nginx部署时,没有名为django.core.wsgi的模块

[英]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. 我尝试了所有事情,但无法解决此错误。我正在用nginx部署django应用程序,但收到此错误。 my wsgi file 我的wsgi文件

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 我的runmicro.ini文件是

[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 micro_nginx文件是

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. django不在您的Python的模块搜索路径中。 To figure out why that is so, I would suggest putting some debug code in your wsgi.py file, here's a start: 为了弄清楚为什么会这样,我建议在您的wsgi.py文件中放入一些调试代码,这是一个开始:

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). (假设您的sys.path或Python是找不到django的原因)。

If you're trying to use a virtualenv, then you need to activate it. 如果您尝试使用virtualenv,则需要激活它。 Here's how I do it (in the wsgi.py file): 这是我的操作方式(在wsgi.py文件中):

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). 我不确定python 3分支的工作情况(从未使用过)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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