无法将目标WSGI脚本作为python模块和ImportError加载:没有名为“ django”的模块

时间:2018-12-11 06:47:08

标签: django apache ubuntu mod-wsgi

我正在尝试通过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):目标WSGI脚本'/ var / www / html / rasa_django / rasa_django / wsgi.py'无法作为Python模块加载。   [Tue Dec 11 11:55:31.748570 2018] [wsgi:error] [pid 14231:tid 139821891782400] [remote :: 1:44748] mod_wsgi(pid = 14231):处理WSGI脚本'/ var / www / html时发生异常/rasa_django/rasa_django/wsgi.py”。   [Tue Dec 11 11:55:31.748639 2018] [wsgi:error] [pid 14231:tid 139821891782400] [remote :: 1:44748] Traceback(最近一次拨打电话):   [Tue Dec 11 11:55:31.748657 2018] [wsgi:error] [pid 14231:tid 139821891782400] [remote :: 1:44748]文件“ /var/www/html/rasa_django/rasa_django/wsgi.py”,行12,在   [Tue Dec 11 11:55:31.748662 2018] [wsgi:error] [pid 14231:tid 139821891782400] [remote :: 1:44748] from django.core.wsgi import get_wsgi_application   [Tue Dec 11 11:55:31.748677 2018] [wsgi:error] [pid 14231:tid 139821891782400] [remote :: 1:44748] ImportError:No module named'django'   [Tue Dec 11 11:55:31.787336 2018] [wsgi:error] [pid 14231:tid 139821849777920] [remote :: 1:38604] mod_wsgi(pid = 14231):目标WSGI脚本'/ var / www / html / rasa_django /rasa_django/wsgi.py'无法作为Python模块加载。   [Tue Dec 11 11:55:31.787379 2018] [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(最近一次拨打电话):   [Tue Dec 11 11:55:31.787465 2018] [wsgi:error] [pid 14231:tid 139821849777920] [remote :: 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   [Tue Dec 11 11:55:31.787484 2018] [wsgi:error] [pid 14231:tid 139821849777920] [remote :: 1:38604] ImportError:没有名为'django'的模块

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

    服务器名称www.rasa_django.com     DocumentRoot / var / www / html / rasa_django     ErrorLog /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')

application = get_wsgi_application()

2 个答案:

答案 0 :(得分:0)

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

尝试:

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

答案 1 :(得分:0)

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