代码之家  ›  专栏  ›  技术社区  ›  Massimiliano

django python mod_wsgi:importorror:没有名为“django”的模块

  •  0
  • Massimiliano  · 技术社区  · 6 年前

    我试图在ubunt16.04u服务器中设置django python环境,但是我得到了apache错误:“importerror:no module named'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)
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   Massimiliano    6 年前

    [已解决]错误是由于wsgi python版本不匹配造成的。apache运行的是另一个版本(python 3.5)。

    我遵循了这些帖子中的建议:

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

    Change mod_wsgi from python3.5 to 3.6