mod_wsgi - 致命的 Python 错误:initfsencoding:无法加载文件系统编解码器 [英] mod_wsgi - Fatal Python error: initfsencoding: unable to load the file system codec
问题描述
使用 Red Hat、apache 2.4.6、worker mpm、mod_wsgi 4.6.5 和 Python 3.7 启动 httpd 时出现上述错误,并且:
Using Red Hat, apache 2.4.6, worker mpm, mod_wsgi 4.6.5, and Python 3.7 When I start httpd I get the above error and:
ModuleNotFoundError: 没有名为encodings"的模块
在 httpd error_log 中.
In the httpd error_log.
我正在使用从我的主目录下的源代码安装的 python 创建的 python 虚拟环境.我使用 --with-python=
选项从源代码安装了 mod_wsgi,指向我的虚拟环境中的 python 二进制文件,然后我将 mod_wsgi.so 文件复制到我的 apache 模块目录中作为 mod_wsgi37.so
I'm using a python virtual environment created from a python installed from source under my home directory. I installed mod_wsgi from source using --with-python=
option pointing to the python binary in my virtual environment, then I copied the mod_wsgi.so file into my apache modules directory as mod_wsgi37.so
我在这个文件上运行了 ldd,并有一个 .conf 文件将它加载到 httpd 中,如下所示:
I ran ldd on this file, and have a .conf file loading it into httpd like this:
LoadFile/home/myUser/pythonbuild/lib/libpython3.7m.so.1.0LoadModule wsgi_module modules/mod_wsgi37.so
然后在我的 VirtualHost 中:
Then within my VirtualHost I have:
WSGIDaemonProcess wsgi group=www threads=12 processes=2 python-path=/var/www/wsgi-scripts python-home=/var/www/wsgi-scripts/wsgi_env3WSGIProcessGroup wsgiWSGIScriptAlias/test/var/www/wsgi-scripts/test.py
来自我的虚拟环境:
sys.prefix:'/var/www/wsgi-scripts/wsgi_env3'
sys.prefix:'/var/www/wsgi-scripts/wsgi_env3'
sys.real_prefix:'/home/myUser/pythonbuild'
sys.real_prefix:'/home/myUser/pythonbuild'
当我切换到系统安装的 mod_wsgi/python 组合(从 WSGIDaemonProcess 中删除 python-home 行,并更改 .conf 文件以加载原始 mod_wsgi.so)时,它工作正常.似乎某些路径变量没有正确设置.有没有另一种方法来设置我缺少的 PYTHONHOME 之类的变量?如何修复我的安装?
When I switch to the system-installed mod_wsgi/python combo (remove python-home line from WSGIDaemonProcess, and change the .conf file to load the original mod_wsgi.so) it works fine. It seems like some path variables aren't getting set properly. Is there another way to set variables like PYTHONHOME that I'm missing? How can I fix my install?
推荐答案
我有一个非常相似的问题,我发现我手动指定的 LoadModule wsgi_module "/path_to_conda/"
被忽略,因为之前的 apache-wide wsgi mod 正在加载.您可以检查 /etc/apache2/mods-enabled
中是否存在 wsgi.*
.
I had a very similar issue and I found that my manually specified LoadModule wsgi_module "/path_to_conda/"
was being ignored because the previously apache-wide wsgi mod was being loaded. You can check if wsgi.*
is present in /etc/apache2/mods-enabled
.
如果是这种情况,请考虑使用 a2dismod wsgi
禁用加载错误 python 的 apache wsgi.
If that is the case, consider a2dismod wsgi
to disable the apache wsgi that loads the wrong python.
这篇关于mod_wsgi - 致命的 Python 错误:initfsencoding:无法加载文件系统编解码器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!