【发布时间】:2016-12-02 16:12:12
【问题描述】:
wsgi.py:
import os,sys
sys.path.append('/var/www/html/yuyyu/yuyyu')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "yuyyu.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
apache.conf:
...
WSGIDaemonProcess yuyyu python-path=/var/www/html/yuyyu
WSGIProcessGroup yuyyu
WSGIScriptAlias / /var/www/html/yuyyu/yuyyu/wsgi.py \
process-group=yuyyu application-group=%{GLOBAL}
...
这是我在 error.log 中的错误:
[Fri Dec 02 19:07:55.862266 2016] [:error] [pid 1414] [remote 213.14.244.3:2784] mod_wsgi (pid=1414): Target WSGI script '/var/www/html/yuyyu/yuyyu/wsgi.py' cannot be loaded as Python module.
[Fri Dec 02 19:07:55.862323 2016] [:error] [pid 1414] [remote 213.14.244.3:2784] mod_wsgi (pid=1414): Exception occurred processing WSGI script '/var/www/html/yuyyu/yuyyu/wsgi.py'.
[Fri Dec 02 19:07:55.862353 2016] [:error] [pid 1414] [remote 213.14.244.3:2784] Traceback (most recent call last):
[Fri Dec 02 19:07:55.862393 2016] [:error] [pid 1414] [remote 213.14.244.3:2784] File "/var/www/html/yuyyu/yuyyu/wsgi.py", line 23, in <module>
[Fri Dec 02 19:07:55.862398 2016] [:error] [pid 1414] [remote 213.14.244.3:2784] from django.core.wsgi import get_wsgi_application
[Fri Dec 02 19:07:55.862418 2016] [:error] [pid 1414] [remote 213.14.244.3:2784] ImportError: No module named 'django'
我的项目路径是/var/www/html/yuyyu/
我的wsgi文件路径是/var/www/html/yuyyu/yuyyu/
我也得到 500 内部服务器错误和 我没有使用 virtualenv,所以我该怎么做才能解决这个问题?
【问题讨论】:
-
你用的是什么python版本?您确定为这个精确版本安装了 django 吗? (例如,在为 python2 安装 django 之后,您确定没有尝试使用 python3 运行 django 吗?)您能否为相关的 python 版本添加
pip freeze输出?您是否还确定如果您为正确的 python 版本安装了django,那么您不是仅为用户安装它,而是为您的整个系统安装它(您没有将--user标志与pip一起使用) -
im using python2 here is pip freeze result:
Django==1.9.7 Landscape-Client==14.12 MySQL-python==1.2.3 PAM==0.4.2 Twisted-Core==13.2.0 apt-xapian-index==0.45 argparse==1.2.1 chardet==2.0.1 colorama==0.2.5 configobj==4.7.2 django-secure==1.0.1 django-sslserver==0.19 html5lib==0.999 pyOpenSSL==0.13 pyserial==2.6 python-apt==0.9.3.5ubuntu2 python-debian==0.1.21-nmu2ubuntu2 requests==2.2.1 six==1.5.2 ssh-import-id==3.21 uWSGI==2.0.14 urllib3==1.7.1 wheel==0.24.0 wsgiref==0.1.2 -
有关使用带有 mod_wsgi 的 Python 虚拟环境的一般信息(推荐),请参阅modwsgi.readthedocs.io/en/develop/user-guides/…
-
与虚拟环境不同,Python 解释器中的
sys.prefix有什么作用?您有 Django 安装输出吗?然后使用 WSGI hello world 找出sys.prefix是什么 mod_wsgi 正在使用。这将确认他们使用的是相同的 Python 安装。