我在 CentOS 6.5 上使用 Apache 2.2.15。我正在尝试使用 mod_wsgi 设置 Django 应用程序。
我正在使用虚拟环境,并且使用 --with-python=/path/to/virtualenv/bin/python3.4
配置了 mod_wsgi。
我已将此添加到我的 httpd.conf
文件中:
WSGIPythonPath /srv/myproject:/path/to/virtualenv/lib/python3.4/site-packages
WSGIPythonHome /path/to/virtualenv
<VirtualHost *:80>
WSGIScriptAlias / /srv/myproject/myproject/wsgi.py
...
</VirtualHost>
在wsgi.py
文件中,我添加了。sys.path.insert(1, "/path/to/virtualenv/lib/python3.4/site-packages")
问题在于当我尝试在浏览器中打开应用程序时,它会无限期地加载。以下是Apache错误日志:
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'
[Mon Jun 30 17:37:28 2014] [notice] child pid 19370 exit signal Aborted (6)
[Mon Jun 30 17:37:28 2014] [notice] child pid 19371 exit signal Aborted (6)
...
[Mon Jun 30 17:37:28 2014] [notice] child pid 19377 exit signal Aborted (6)
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'
有趣的是,在 Python (2.6) 的系统安装和虚拟环境版本 (3.4) 中,import encodings
都能正常工作!我尝试使用 mod_wsgi CheckingYourInstallation 页面上的示例 WSGI 脚本 来确认 Apache 正在使用哪个版本的 Python,但我得到了相同的 ImportError。有人有什么建议吗?我已经搜遍了文档,但不知道下一步该去哪里。