【问题标题】:Target WSGI script cannot be loaded as a python module and ImportError: No module named 'django'目标 WSGI 脚本无法作为 python 模块加载并且 ImportError: No module named 'django'
【发布时间】:2019-05-12 03:04:12
【问题描述】:

我正在尝试通过 mod_wsgi WSGIDaemon 方法将我的 django 项目的虚拟主机部署到 apache2 中,我使用的是 ubuntu 16.04,但出现以下错误。

来自 apache2 错误日志:

[2018 年 12 月 11 日星期二 11:55:31.748517] [wsgi:error] [pid 14231:tid 139821891782400] [remote ::1:44748] mod_wsgi (pid=14231): Target WSGI script '/var/www/ html/rasa_django/rasa_django/wsgi.py' 不能作为 Python 模块加载。 [2018 年 12 月 11 日星期二 11:55:31.748570] [wsgi:error] [pid 14231:tid 139821891782400] [remote ::1:44748] mod_wsgi (pid=14231): 处理 WSGI 脚本'/var/www/html 时发生异常/rasa_django/rasa_django/wsgi.py'。 [2018 年 12 月 11 日星期二 11:55:31.748639] [wsgi:error] [pid 14231:tid 139821891782400] [remote ::1:44748] Traceback(最近一次通话最后): [2018 年 12 月 11 日星期二 11:55:31.748657] [wsgi:error] [pid 14231:tid 139821891782400] [远程 ::1:44748] 文件“/var/www/html/rasa_django/rasa_django/wsgi.py”,行12、在 [2018 年 12 月 11 日星期二 11:55:31.748662] [wsgi:error] [pid 14231:tid 139821891782400] [remote ::1:44748] from django.core.wsgi import get_wsgi_application [2018 年 12 月 11 日星期二 11:55:31.748677] [wsgi:error] [pid 14231:tid 139821891782400] [remote ::1:44748] ImportError: No module named 'django' [2018 年 12 月 11 日星期二 11:55:31.787336] [wsgi:error] [pid 14231:tid 139821849777920] [remote ::1:38604] mod_wsgi (pid=14231): Target WSGI script '/var/www/html/rasa_django /rasa_django/wsgi.py' 不能作为 Python 模块加载。 [2018 年 12 月 11 日星期二 11:55:31.787379] [wsgi:error] [pid 14231:tid 139821849777920] [remote ::1:38604] mod_wsgi (pid=14231): 处理 WSGI 脚本'/var/www/html 时发生异常/rasa_django/rasa_django/wsgi.py'。 [2018 年 12 月 11 日星期二 11:55:31.787447] [wsgi:error] [pid 14231:tid 139821849777920] [remote ::1:38604] Traceback(最近一次通话最后): [2018 年 12 月 11 日星期二 11:55:31.787465] [wsgi:error] [pid 14231:tid 139821849777920] [远程 ::1:38604] 文件“/var/www/html/rasa_django/rasa_django/wsgi.py”,行12、在 [2018 年 12 月 11 日星期二 11:55:31.787470] [wsgi:error] [pid 14231:tid 139821849777920] [remote ::1:38604] from django.core.wsgi import get_wsgi_application [2018 年 12 月 11 日星期二 11:55:31.787484] [wsgi:error] [pid 14231:tid 139821849777920] [remote ::1:38604] ImportError: No module named 'django'

在我的主机文件 000-default.conf 中:

服务器名称 www.rasa_django.com DocumentRoot /var/www/html/rasa_django 错误日志 /var/www/logs/error.log CustomLog /var/www/logs/custom.log 合并

Alias /static /var/www/html/rasa_django/static

<Directory /var/www/html/rasa_django/static>
    Require all granted
</Directory>

<Directory /var/www/html/rasa_django/rasa_django>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>

WSGIDaemonProcess rasa_django.com python-path=/var/www/html/rasa_django python-home=/home/aarbor_01/env_site1/lib/python3.6/site-packages
WSGIProcessGroup rasa_django.com
WSGIScriptAlias / /var/www/html/rasa_django/rasa_django/wsgi.py

这是我的 wsgi.py 文件:

导入操作系统

从 django.core.wsgi 导入 get_wsgi_application

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

应用程序 = get_wsgi_application()

【问题讨论】:

    标签: django apache ubuntu mod-wsgi


    【解决方案1】:

    我通过链接https://github.com/GrahamDumpleton/mod_wsgi/issues/378解决了这个问题

    【讨论】:

      【解决方案2】:

      根据docs,如果您使用的是虚拟环境(我假设env_site1 是),那么您应该将python-home 指向该环境的根目录。

      试试:

      WSGIDaemonProcess rasa_django.com python-path=/var/www/html/rasa_django python-home=/home/aarbor_01/env_site1
      

      【讨论】:

      • @Aarbor1 你用的是什么版本的 mod_wsgi?
      • 我使用的是 mod-wsgi==4.​​6.5 版本
      猜你喜欢
      • 2018-07-20
      • 1970-01-01
      • 2016-12-23
      • 2016-12-19
      • 2018-01-18
      • 2017-03-31
      • 2011-09-21
      • 1970-01-01
      相关资源
      最近更新 更多