【发布时间】:2011-06-23 04:40:36
【问题描述】:
我正在尝试设置 apache、mod_wsgi 和 django。我的 apache 错误日志中出现内部服务器错误:
[Wed Jun 22 21:31:55 2011] [error] [client ::1] mod_wsgi (pid=2893): Target WSGI script '/django/internal/django-development.wsgi' cannot be loaded as Python module.
[Wed Jun 22 21:31:55 2011] [error] [client ::1] mod_wsgi (pid=2893): Exception occurred processing WSGI script '/django/internal/django-development.wsgi'.
[Wed Jun 22 21:31:55 2011] [error] Traceback (most recent call last):
[Wed Jun 22 21:31:55 2011] [error] File "/django/internal/django-development.wsgi", line 3, in <module>
[Wed Jun 22 21:31:55 2011] [error] import sys, os
[Wed Jun 22 21:31:55 2011] [error] ImportError: No module named os
[Wed Jun 22 21:31:55 2011] [error] [client ::1] mod_wsgi (pid=2893): Target WSGI script '/django/internal/django-development.wsgi' cannot be loaded as Python module.
[Wed Jun 22 21:31:55 2011] [error] [client ::1] mod_wsgi (pid=2893): Exception occurred processing WSGI script '/django/internal/django-development.wsgi'.
[Wed Jun 22 21:31:55 2011] [error] Traceback (most recent call last):
[Wed Jun 22 21:31:55 2011] [error] File "/django/internal/django-development.wsgi", line 3, in <module>
[Wed Jun 22 21:31:55 2011] [error] import sys, os
[Wed Jun 22 21:31:55 2011] [error] ImportError: No module named os
django-development.wsgi
#! /usr/bin/env python
import sys, os
path = '/django/internal'
if path not in sys.path:
sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'internal.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
如果有任何东西(例如配置文件)我可以发布以帮助您诊断此问题,请告诉我。
编辑:
这很奇怪,考虑到我认为我将默认 python 版本设置为 2.5..,并以 python2.5 作为参数运行 ./configure
$otool -L mod_wsgi.somod_wsgi.so:
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.10)
/System/Library/Frameworks/Python.framework/Versions/2.6/Python (compatibility version 2.6.0, current version 2.6.1)
和
LoadModule wsgi_module libexec/apache2/mod_wsgi.so
WSGIScriptAlias / /django/internal/django-development.wsgi
编辑:
啊,好像正在导入错误的配置文件。我已经得到它现在给我以下输出。进展:
[Wed Jun 22 23:04:28 2011] [error] Exception ImportError: 'No module named atexit' in 'garbage collection' ignored
Fatal Python error: unexpected exception during garbage collection
[Wed Jun 22 23:04:28 2011] [error] Exception ImportError: 'No module named atexit' in 'garbage collection' ignored
Fatal Python error: unexpected exception during garbage collection
[Wed Jun 22 23:04:29 2011] [notice] caught SIGTERM, shutting down
[Wed Jun 22 23:04:29 2011] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
[Wed Jun 22 23:04:29 2011] [warn] mod_wsgi: Compiled for Python/2.5.4.
[Wed Jun 22 23:04:29 2011] [warn] mod_wsgi: Runtime using Python/2.6.1.
[Wed Jun 22 23:04:29 2011] [notice] Digest: generating secret for digest authentication ...
[Wed Jun 22 23:04:29 2011] [notice] Digest: done
[Wed Jun 22 23:04:29 2011] [notice] Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8l DAV/2 mod_wsgi/3.3 Python/2.6.1 configured -- resuming normal operations
[Wed Jun 22 23:06:04 2011] [error] [client ::1] client denied by server configuration: /django/internal/django-development.wsgi
编辑
所以,我仍然想弄清楚如何让 mod_wsgi 运行 python 2.5 而不是 2.6——这就是我现在遇到的大问题。除此之外,它应该只是调整 apache 配置。
【问题讨论】:
-
什么版本的python?你能用普通的python解释器
import os吗? -
2.5 版——是的,我可以。
-
能否包含与
django-development.wsgi在同一目录中的文件列表? -
它实际上是我的整个 django 站点——我应该把它放在一个单独的目录中吗?
-
您的python安装似乎没有安装
os模块。这是您的python安装的问题。您使用的是哪个操作系统和 python?
标签: python django apache mod-wsgi