Ubuntu + Python3.6 + Apache2_web访问错误:没有名为django.core.wsgi的模块

时间:2017-09-08 17:03:54

标签: django mod-wsgi wsgi python-3.6

Ubuntu16(x64)+ Python3.6(由anaconda安装)+ Django1.11.3(由conda安装)+ Apache2.4.18。

使用此配置_ect / apache2 / site-available / 000-default.conf

<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/mblog

WSGIDaemonProcess mblog python-path=/var/www/mblog
WSGIProcessGroup mblog

WSGIScriptAlias / /var/www/mblog/mblog/wsgi.py

<Directory /var/www/mblog/mblog>
<Files wsgi.py>
Order deny,allow
Require all granted
</Files>
</Directory>            
</VirtualHost>

和python项目的apache www目录如下:

enter code here/var/www/mblog/(755)
|-- manage.py(755)
|       
|-- mblog(dir 755)
|      `|-- wsgi.py(644)
|       `-- urls.py(644)
|-- templates(dir)
|       `-- *.html(644)

wsgi.py配置如下(文件被授予):

import os, sys
sys.path.append('/var/www/mblog/mblog')

# poiting to the project settings
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mblog.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

完成所有这些配置后,浏览器显示:“500 Internal Server Error”

所以我查找/var/log/apache2/error.log的错误如下:

File "/var/www/mblog/mblog/wsgi.py", line 31, in <module>
from django.core.wsgi import get_wsgi_application
ImportError: No module named django.core.wsgi

我对网站解释的所有解释感到困惑,但所有这些都无法解决这个问题。

https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/modwsgi/

你可以帮我解决这个问题吗? 谢谢!

1 个答案:

答案 0 :(得分:0)

您要么没有告诉mod_wsgi您正在使用的Python虚拟环境以及安装了哪些Django,要么您的mod_wsgi是针对不同版本的Python编译的,而不是您要使用的Python以及安装的Python。

通过执行以下所述操作来检查编译的mod_wsgi:

有关如何设置Python虚拟环境(建议使用),请参阅:

相关问题