簡體   English   中英

Django Python mod_wsgi:ImportError:沒有名為“ django”的模塊

[英]Django Python mod_wsgi: ImportError: No module named 'django'

我正在嘗試在Ubunt16.04u服務器中設置Django-Python環境,但出現Apache錯誤:“ ImportError:沒有名為'django'的模塊”我已經安裝了Python 3.7,virtualenv(sudo pip install virtualenv),Django (pip install Django),mod_wsgi(sudo make install)。

可能是該問題的原因?

// Apache錯誤日志文件

[Wed Nov 21 17:45:07.572605 2018] [wsgi:error] [pid 60818] [remote 192.168.224.1:56398] mod_wsgi (pid=60818): Target WSGI script '/var/www/django_virtualenv/progetti_django/curriculum/curriculum/wsgi.py' cannot be loaded as Python module.
[Wed Nov 21 17:45:07.572638 2018] [wsgi:error] [pid 60818] [remote 192.168.224.1:56398] mod_wsgi (pid=60818): Exception occurred processing WSGI script '/var/www/django_virtualenv/progetti_django/curriculum/curriculum/wsgi.py'.
[Wed Nov 21 17:45:07.572758 2018] [wsgi:error] [pid 60818] [remote 192.168.224.1:56398] Traceback (most recent call last):
[Wed Nov 21 17:45:07.572805 2018] [wsgi:error] [pid 60818] [remote 192.168.224.1:56398]   File "/var/www/django_virtualenv/progetti_django/curriculum/curriculum/wsgi.py", line 17, in <module>
[Wed Nov 21 17:45:07.572812 2018] [wsgi:error] [pid 60818] [remote 192.168.224.1:56398]     from django.core.wsgi import get_wsgi_application
[Wed Nov 21 17:45:07.572824 2018] [wsgi:error] [pid 60818] [remote 192.168.224.1:56398] ImportError: No module named 'django'

// Apache配置文件

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.

    ServerAdmin webmaster@example.com
    ServerName cv-django.vmware
    ServerAlias www.cv-django.vmware
    DocumentRoot /var/www/django_virtualenv/progetti_django/curriculum/cv
    WSGIScriptAlias / /var/www/django_virtualenv/progetti_django/curriculum/curriculum/wsgi.py

    WSGIDaemonProcess cv-django.vmware processes=2 threads=15 display-name=%{GROUP} python-home=/var/www/djang$
    WSGIProcessGroup cv-django.vmware

    <Directory />
            Options FollowSymLinks
            AllowOverride All
    </Directory>

    <Directory /var/www/django_virtualenv/progetti_django/curriculum/cv/>
            Options FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
    </Directory>


    Alias /static/ /var/www/django_virtualenv/progetti_django/curriculum/cv/static/

     <Directory /var/www/django_virtualenv/progetti_django/curriculum/cv/static>
      Require all granted
     </Directory>

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    ServerSignature On



    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

//wsgi.py

import os
import time
import traceback
import signal
import sys


from django.core.wsgi import get_wsgi_application

sys.path.append('/var/www/django_virtualenv/progetti_django/curriculum/cv')

sys.path.append('/var/www/django_virtualenv/progetti_django/lib/python3.7/site-packages')

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'curriculum.settings')

try:
    application = get_wsgi_application()
except Exception:
    # Error loading applications
    if 'mod_wsgi' in sys.modules:
        traceback.print_exc()
        os.kill(os.getpid(), signal.SIGINT)
        time.sleep(2.5)

[已解決]該錯誤是由於wsgi python版本不匹配所致。 Apache運行的是其他版本(Python 3.5)。

我遵循了這些帖子中的建議:

https://stackoverflow.com/posts/28118284/revisions

將mod_wsgi從python3.5更改為3.6

暫無
暫無

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

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