我在Windows 7 Home Prime Edition 64位环境中遇到此错误。如Apache文档中所述,我尝试了许多不同的方式。在httpd.conf中,我有以下环境Python 3.4,Apache 2.4.25mod_wsgi py25 vc10 64位。此外,我试图运行Python代码通过CGI,它运行良好。
LoadModule wsgi_module modules/mod_wsgi.so
WSGIPythonEggs /apache2423/Apache24/htdocs
WSGIScriptAlias /wsgi /apache2423/Apache24/htdocs/wsgi.py
WSGIPythonPath /Python34
<Directory /apache2423/Apache24/htdocs/>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
代码是:
#!/Python34/python
import os
import subprocess
os.environ['PYTHON_EGG_CACHE'] = '/Apache245/Apache24/htdocs'
def application(environ, start_response):
status = '200 OK'
output = b'<html> ... Hello World of Django ...</html>'
response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
假定mod_wsgi.so
文件正确在Apache模块目录中,将Apache配置更改为:
LoadFile /Python34/DLLs/python3.dll
LoadModule wsgi_module modules/mod_wsgi.so
WSGIPythonHome /Python34
WSGIScriptAlias /wsgi /apache2423/Apache24/htdocs/wsgi.py
<Directory /apache2423/Apache24/htdocs/>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
确认:
/Python34/DLLs/python3.dll
确实存在。它应该是python 3.4 dll的位置。
假定您的Python 3.4安装在/Python34
下。
LoadFile
线的点是强制python dll的加载。您获得的错误也可能意味着它是mod_wsgi.so
引用的DLL,在任何标准位置都找不到。
WSGIPythonHome
告诉MOD_WSGI python安装在哪里。请注意,它不是您所拥有的WSGIPythonPath
。
您将用于访问应用程序的URL为http://localhost/wsgi
。