簡體   English   中英

ImportError:使用nginx部署時,沒有名為django.core.wsgi的模塊

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

這個問題問保存時間。 我嘗試了所有事情,但無法解決此錯誤。我正在用nginx部署django應用程序,但收到此錯誤。 我的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()

我收到此錯誤

[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 ***

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

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;

        }
}

請幫我解決這個問題

好吧,錯誤很簡單:

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不在您的Python的模塊搜索路徑中。 為了弄清楚為什么會這樣,我建議在您的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]

(假設您的sys.path或Python是找不到django的原因)。

如果您嘗試使用virtualenv,則需要激活它。 這是我的操作方式(在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))

我不確定python 3分支的工作情況(從未使用過)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM