在 Windows Server 2008 R2、Python 3.3 和 Apache 2.2 上运行 Django 1.5 时,出现错误。错误信息如下:
[Sun Nov 10 13:26:46 2013] [error] [client 127.0.0.1] mod_wsgi (pid=8768): Target WSGI script 'C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/mysite/mysite/wsgi.py' cannot be loaded as Python module.
[Sun Nov 10 13:26:46 2013] [error] [client 127.0.0.1] mod_wsgi (pid=8768): Exception occurred processing WSGI script 'C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/mysite/mysite/wsgi.py'.
[Sun Nov 10 13:26:46 2013] [error] [client 127.0.0.1] Traceback (most recent call last):\r
[Sun Nov 10 13:26:46 2013] [error] [client 127.0.0.1] File "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/mysite/mysite/wsgi.py", line 10, in <module>\r
[Sun Nov 10 13:26:46 2013] [error] [client 127.0.0.1] import django.core.handlers.wsgi\r
[Sun Nov 10 13:26:46 2013] [error] [client 127.0.0.1] File "C:\Python33\lib\site-packages\django\core\handlers\wsgi.py", line 9, in <module>\r
[Sun Nov 10 13:26:46 2013] [error] [client 127.0.0.1] from django import http\r
[Sun Nov 10 13:26:46 2013] [error] [client 127.0.0.1] File "C:\Python33\lib\site-packages\django\http\__init__.py", line 2, in <module>\r
[Sun Nov 10 13:26:46 2013] [error] [client 127.0.0.1] from django.http.request import (HttpRequest, QueryDict, UnreadablePostError,\r
[Sun Nov 10 13:26:46 2013] [error] [client 127.0.0.1] File "C:\Python33\lib\site-packages\django\http\request.py", line 20, in <module>\r
[Sun Nov 10 13:26:46 2013] [error] [client 127.0.0.1] from django.http.multipartparser import MultiPartParser\r
[Sun Nov 10 13:26:46 2013] [error] [client 127.0.0.1] File "C:\Python33\lib\site-packages\django\http\multipartparser.py", line 10, in <module>\r
[Sun Nov 10 13:26:46 2013] [error] [client 127.0.0.1] import cgi\r
[Sun Nov 10 13:26:46 2013] [error] [client 127.0.0.1] File "C:\Python33\Lib\cgi.py", line 38, in <module>\r
[Sun Nov 10 13:26:46 2013] [error] [client 127.0.0.1] from email.parser import FeedParser\r
[Sun Nov 10 13:26:46 2013] [error] [client 127.0.0.1] File "C:\Python33\Lib\email\parser.py", line 12, in <module>\r
[Sun Nov 10 13:26:46 2013] [error] [client 127.0.0.1] from email.feedparser import FeedParser, BytesFeedParser\r
[Sun Nov 10 13:26:46 2013] [error] [client 127.0.0.1] File "C:\Python33\Lib\email\feedparser.py", line 27, in <module>\r
[Sun Nov 10 13:26:46 2013] [error] [client 127.0.0.1] from email import message\r
[Sun Nov 10 13:26:46 2013] [error] [client 127.0.0.1] File "C:\Python33\Lib\email\message.py", line 16, in <module>\r
[Sun Nov 10 13:26:46 2013] [error] [client 127.0.0.1] from email import utils\r
[Sun Nov 10 13:26:46 2013] [error] [client 127.0.0.1] File "C:\Python33\Lib\email\utils.py", line 30, in <module>\r
[Sun Nov 10 13:26:46 2013] [error] [client 127.0.0.1] import socket\r
[Sun Nov 10 13:26:46 2013] [error] [client 127.0.0.1] File "C:\Python33\Lib\socket.py", line 47, in <module>\r
[Sun Nov 10 13:26:46 2013] [error] [client 127.0.0.1] import _socket\r
[Sun Nov 10 13:26:46 2013] [error] [client 127.0.0.1] ImportError: DLL load failed: %1 nen\xc3\xad platn\xc3\xa1 aplikace typu Win32.\r
- 解决方案
错误的原因可能是 32 位/64 位不兼容。请仔细检查您是否已将 Windows、Apache、Python 和 mod_wsgi 安装或构建为 32 位或 64 位,并且没有将这两种类型混合使用。
以下是解决此问题的步骤:
- 检查您的 Windows 版本是 32 位还是 64 位。您可以通过右键单击“我的电脑”,然后选择“属性”来找到此信息。
- 检查您的 Apache 版本是 32 位还是 64 位。您可以通过打开 Apache 配置文件并查找以下行来找到此信息:
LoadModule wsgi_module modules/mod_wsgi.so
如果该行中的路径是 32 位,则您的 Apache 版本是 32 位。如果该行中的路径是 64 位,则您的 Apache 版本是 64 位。 3. 检查您的 Python 版本是 32 位还是 64 位。您可以通过打开 Python 解释器并运行以下命令来找到此信息:
import platform
print(platform.architecture())
- 检查您的 mod_wsgi 版本是 32 位还是 64 位。您可以通过打开 mod_wsgi 配置文件并查找以下行来找到此信息:
WSGIScriptAlias / /var/www/myapp/myapp/wsgi.py
如果该行中的路径是 32 位,则您的 mod_wsgi 版本是 32 位。如果该行中的路径是 64 位,则您的 mod_wsgi 版本是 64 位。 5. 确保您已将 Windows、Apache、Python 和 mod_wsgi 安装或构建为相同类型的位(32 位或 64 位)。如果您已将它们混合使用,则需要重新安装或重新构建它们。
重新安装或重新构建 Windows、Apache、Python 和 mod_wsgi 后